Open onur-ozkan opened 2 years ago
PS: For x86 family(and probably some arm families specially modern ones if I am not mistaken) compare_exchange
has single atomic instruction which reduces the overhead. But still heavier than just loading the value.
compare_exchange
is quite heavy operation which should never spin in a loop over and over like here here on multi-threaded systems. Since it tries to have exclusive access to the desired memory location, the running threads have to try getting that access over and over. Which is obviously not an efficent way to do so.There are many things can be done on this implementation to make it more efficent. Like instead of trying
compare_exchange
it can be replaced with thecompare_exchange_weak
function (this performs little bit better on some platforms and there is no problem with using it if it's running under the loop). But still, it should not be executed over and over since we don't want to make our threads wasting too much power for exclusive access.An efficent way to use
compare_exchange_weak
(dummy code):ToDos:
compare_exchange
usages should be checked and optimized.cc @artemii235 @sergeyboyko0791 @shamardy