08.12.2015 16:41, Dimitry Sibiryakov wrote:
> 08.12.2015 15:31, Vlad Khorsun wrote:
>>      This code is not the same as code that you blamed and it is not correct 
>> at all.
>
>     At first, I don't blame your code. It is robust and fast enough. It is 
> just a little

   Good to know, i had another opinion before ;)

> confusing at first glance and leave some more room for threads racing if you 
> take into
> consideration other possible flags.

   I see no races there. Especially considering another flags.

>     At second, this code is correct because cleanSweepFlags() will clear both 
> flags anyway.

   No. Code you show is from Database::allowSweepThread() (and i discuss that 
code):

        while (true)
        {
                AtomicCounter::counter_type old = dbb_flags;
                if ((old & (DBB_sweep_in_progress | DBB_sweep_starting)) || 
(dbb_ast_flags & DBB_shutdown))
                        return false;

                if (dbb_flags.compareExchange(old, old | DBB_sweep_starting))
                        break;
        }

   This code must not set DBB_sweep_starting flag if it not going to start 
sweep thread.
I.e. if sweep thread:
- already starting
- already started
- not allowed due to database shutdown

   With your proposed simplification, code will set DBB_sweep_starting flag in 
any case,
even if this thread will not continue. Thus your code is not equal to code 
above and
not correct.

   Note, cleanSweepFlags() is never called after Database::allowSweepThread(). 
It is called after
another method - Database::allowSweepRun()

Regards,
Vlad

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to