08.12.2015 12:26, Dimitry Sibiryakov wrote:
>     Hello, All.
>
>     Currently to do subj, code like this is used:
>
>>              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;
>>              }
>
>     Is there a reason not to use _InterlockedOr() intrinsic with MSVC and
> __sync_or_and_fetch() with GCC for such cases?

   Here we need to know if flag was set by our thread or another one, therefore 
we must use compare_exchange.


   Note, with MSVC, when return value of _InterlockedOr() intrinsic is used by 
the caller, compiler will
generate almost the same code as above (with a loop and compare_exchange). 
Read, for example:

http://blogs.msdn.com/b/doronh/archive/2006/11/10/the-case-of-amazingly-morphing-intrinsic-function.aspx


   With GCC, you suggest to use wrong function : __sync_or_and_fetch() will 
return *new* value, while
we need an old value. Correct function is __sync_fetch_and_or(), see:

https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html

But __sync_fetch_and_or() give us no guarantee because it perform two actions 
which is not atomic together.

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