简体   繁体   中英

Are Win32 InterlockedIncrement and InterlockedExchange atomic across processes?

MSDN says that the interlocked functions provide a simple mechanism for synchronizing access to a variable that is shared by multiple threads.

I am not sure if they work across threads of multiple processes if the variable is in the shared memory of the processes.

Similarly what about GNU GCC compiler intrinsic: __sync_add_and_fetch and __sync_lock_test_and_set?

This question is essentially two questions for two different answers.

  1. For __sync_XXX builtins in GCC answer is yes.

Refer to any online doc like this , where described, that these builtins are normally issuing full barrier, preventing even internal speculating loads inside processor pipeline. Every and all multi-thread, multi-process, etc. shared memory is safe with them.

  1. I know nothing about Windows InterLockedXXX functions. But MSDN knows, and says:

The threads of different processes can use this mechanism if the variable is in shared memory

So both answers are "yes".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM