TSan error with boost::interprocess::message_queue on macOS ARM
Hello List,
I'm using the boost::interprocess::message_queue in a project and to
verify everything is working I created a test case. In that test case
I'm sending and receiving data via threads.
The test passes on Linux, Windows with no sanitizer and also with
AddressSanitizer and ThreadSanitizer. I recently added Apple Silicon
(M1) to the test matrix and now the test run with ThreadSanitizer
enabled fails.
Is boost::interprocess::message_queue thread-safe?
Can the reported TSan error be an false-positive?
If it that case, what test can I run to verify that?
I looked at code of atomic_cas32() and it uses the legacy built-in
__sync_val_compare_and_swap().
Can it be that that built-in isn't supported on ARM?
Is there a newer built-in which should be used?
The reported TSan error:
-- snip
==================
WARNING: ThreadSanitizer: data race (pid=4146)
Atomic write of size 4 at 0x000104af4028 by thread T2:
#0 __tsan_atomic32_compare_exchange_val <null>:81245684
(libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x57854)
#1 boost::interprocess::ipcdetail::atomic_cas32(unsigned int
volatile*, unsigned int, unsigned int) atomic.hpp:581
(tsan_boost:arm64+0x100005b30)
Previous read of size 4 at 0x000104af4028 by thread T1:
#0 boost::interprocess::ipcdetail::spin_mutex::try_lock()
mutex.hpp:100 (tsan_boost:arm64+0x100006eb0)
#1 void
boost::interprocess::ipcdetail::try_based_lockboost::interprocess::ipcdetail::spin_mutex(boost::interprocess::ipcdetail::spin_mutex&)
common_algorithms.hpp:62 (tsan_boost:arm64+0x100006e28)
SUMMARY: ThreadSanitizer: data race atomic.hpp:581 in
boost::interprocess::ipcdetail::atomic_cas32(unsigned int volatile*,
unsigned int, unsigned int)
-- snap
Here is a code example which demonstrates the test case
-- snip
#include
On 09/08/2022 23:35, vl01--- via Boost-users wrote:
Hello List,
I'm using the boost::interprocess::message_queue in a project and to verify everything is working I created a test case. In that test case I'm sending and receiving data via threads.
The test passes on Linux, Windows with no sanitizer and also with AddressSanitizer and ThreadSanitizer. I recently added Apple Silicon (M1) to the test matrix and now the test run with ThreadSanitizer enabled fails.
Is boost::interprocess::message_queue thread-safe? Can the reported TSan error be an false-positive? If it that case, what test can I run to verify that?
I looked at code of atomic_cas32() and it uses the legacy built-in __sync_val_compare_and_swap(). Can it be that that built-in isn't supported on ARM? Is there a newer built-in which should be used?
It could be. Can you test if __atomic_compare_exchange avoids the TSAN error? inline boost::uint32_t atomic_cas32 ( volatile boost::uint32_t *mem , boost::uint32_t with, boost::uint32_t cmp) { __atomic_compare_exchange (const_castboost::uint32_t*(mem), &cmp, &with, false ,__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return cmp; } Best, Ion
On 8/23/22 08:37, Ion Gaztañaga via Boost-users wrote:
I looked at code of atomic_cas32() and it uses the legacy built-in __sync_val_compare_and_swap(). Can it be that that built-in isn't supported on ARM? Is there a newer built-in which should be used?
It could be. Can you test if __atomic_compare_exchange avoids the TSAN error?
inline boost::uint32_t atomic_cas32 ( volatile boost::uint32_t *mem , boost::uint32_t with, boost::uint32_t cmp) { __atomic_compare_exchange (const_castboost::uint32_t*(mem), &cmp, &with, false ,__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return cmp; }
I changed the code as you suggested, but I still get the same error. Cheers, Jens
On 07/09/2022 20:33, Jens Carl via Boost-users wrote:
On 8/23/22 08:37, Ion Gaztañaga via Boost-users wrote:
I looked at code of atomic_cas32() and it uses the legacy built-in __sync_val_compare_and_swap(). Can it be that that built-in isn't supported on ARM? Is there a newer built-in which should be used?
It could be. Can you test if __atomic_compare_exchange avoids the TSAN error?
inline boost::uint32_t atomic_cas32 ( volatile boost::uint32_t *mem , boost::uint32_t with, boost::uint32_t cmp) { __atomic_compare_exchange (const_castboost::uint32_t*(mem), &cmp, &with, false ,__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return cmp; }
I changed the code as you suggested, but I still get the same error.
Cheers, Jens
Sorry to hear that. I'm afraid I've run out of ideas :-(
participants (3)
-
Ion Gaztañaga
-
Jens Carl
-
vl01@jens-carl.de