Reading through the code here, I noted the following implementation of LightweightSemaphore::tryWait():
|
return (oldCount > 0 && m_count.compare_exchange_strong(oldCount, oldCount - 1, std::memory_order_acquire)); |
If I am not mistaken, it is possible for another thread to signal between the load and the compare_exchange_strong which would result in a spurious failure. I think this is commonly referred to as a "weak-try" but if that was the intent then using compare_exchange_weak would be sufficient. I only see this code being used in one single place in this project, and in that instance the strong/weak distinction wouldn't be relevant.
I'm certainly no expert on the topic of C++11 atomic operations, so I could be mistaken.
Reading through the code here, I noted the following implementation of
LightweightSemaphore::tryWait():cpp11-on-multicore/common/sema.h
Line 201 in 41ac9c7
If I am not mistaken, it is possible for another thread to signal between the
loadand thecompare_exchange_strongwhich would result in a spurious failure. I think this is commonly referred to as a "weak-try" but if that was the intent then usingcompare_exchange_weakwould be sufficient. I only see this code being used in one single place in this project, and in that instance the strong/weak distinction wouldn't be relevant.I'm certainly no expert on the topic of C++11 atomic operations, so I could be mistaken.