On 11/9/2023 12:12 AM, Chris M. Thomasson wrote:
> #include <iostream>
> #include <relacy/relacy.hpp>
>
>
> #define CT_THREAD_N 3
>
>
> // Testing Alex's mutex work from over on
> // comp.programming.threads wrt windows...
> // its on
https://sourceware.org/pthreads-win32/
> // anyway....
>
> struct ct_alex_mutex_test_windows
> {
> [...]
> void lock()
> {
> if (m_state.exchange(1, rl::mo_relaxed, $))
> {
> while (m_state.exchange(2, rl::mo_relaxed, $))
> {
> rl_WaitForSingleObject(m_waitset, INFINITE, $);
> }
> }
>
> rl::atomic_thread_fence(rl::mo_acquire, $);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> }
[...]
Relacy kicks some ass. If I comment out that acquire thread fence:
rl::atomic_thread_fence(rl::mo_acquire, $);
Relacy knows things are really wrong here, and gives me the following
output:
Nice!
_______________________________
Relacy Testing 123... ;^)
struct ct_relacy_test_fun
DATA RACE (data race detected)
iteration: 1
execution history (16):
[0] 0: [CTOR BEGIN], in rl::context_impl<struct ct_relacy_test_fun,class
rl::full_search_scheduler<3> >::fiber_proc_impl, context.hpp(457)
[1] 0: memory allocation: addr=0000022E2E825B60, size=24, in
ct_alex_mutex_test_windows::ct_alex_mutex_test_windows, ct_main.cpp(19)
[2] 0: <0000022E2E81C890> atomic store, value=0, (prev value=0),
order=relaxed, in rl::atomic<unsigned long>::atomic, atomic.hpp(594)
[3] 0: [CTOR END], in rl::context_impl<struct ct_relacy_test_fun,class
rl::full_search_scheduler<3> >::fiber_proc_impl, context.hpp(457)
[4] 0: [BEFORE BEGIN], in rl::context_impl<struct
ct_relacy_test_fun,class rl::full_search_scheduler<3>
>::fiber_proc_impl, context.hpp(457)
[5] 0: <0000022E2E81C870> store, value=0, in ct_relacy_test_fun::before,
ct_main.cpp(63)
[6] 0: [BEFORE END], in rl::context_impl<struct ct_relacy_test_fun,class
rl::full_search_scheduler<3> >::fiber_proc_impl, context.hpp(457)
[7] 0: <0000022E2E81C890> exchange , prev=0, arg=1, new=1,
order=relaxed, in ct_alex_mutex_test_windows::lock, ct_main.cpp(32)
[8] 0: <0000022E2E81C870> load, value=0, in ct_relacy_test_fun::thread,
ct_main.cpp(78)
[9] 0: <0000022E2E81C870> store, value=1, in ct_relacy_test_fun::thread,
ct_main.cpp(78)
[10] 0: release fence, in ct_alex_mutex_test_windows::unlock,
ct_main.cpp(45)
[11] 0: <0000022E2E81C890> exchange , prev=1, arg=0, new=0,
order=relaxed, in ct_alex_mutex_test_windows::unlock, ct_main.cpp(47)
[12] 0: [THREAD FINISHED], in rl::context_impl<struct
ct_relacy_test_fun,class rl::full_search_scheduler<3>
>::fiber_proc_impl, context.hpp(457)
[13] 1: <0000022E2E81C890> exchange , prev=0, arg=1, new=1,
order=relaxed, in ct_alex_mutex_test_windows::lock, ct_main.cpp(32)
[14] 1: <0000022E2E81C870> load, value=0, in ct_relacy_test_fun::thread,
ct_main.cpp(78)
[15] 1: DATA RACE (data race detected), in ct_relacy_test_fun::thread,
ct_main.cpp(78)
thread 0:
[0] 0: [CTOR BEGIN], in rl::context_impl<struct ct_relacy_test_fun,class
rl::full_search_scheduler<3> >::fiber_proc_impl, context.hpp(457)
[1] 0: memory allocation: addr=0000022E2E825B60, size=24, in
ct_alex_mutex_test_windows::ct_alex_mutex_test_windows, ct_main.cpp(19)
[2] 0: <0000022E2E81C890> atomic store, value=0, (prev value=0),
order=relaxed, in rl::atomic<unsigned long>::atomic, atomic.hpp(594)
[3] 0: [CTOR END], in rl::context_impl<struct ct_relacy_test_fun,class
rl::full_search_scheduler<3> >::fiber_proc_impl, context.hpp(457)
[4] 0: [BEFORE BEGIN], in rl::context_impl<struct
ct_relacy_test_fun,class rl::full_search_scheduler<3>
>::fiber_proc_impl, context.hpp(457)
[5] 0: <0000022E2E81C870> store, value=0, in ct_relacy_test_fun::before,
ct_main.cpp(63)
[6] 0: [BEFORE END], in rl::context_impl<struct ct_relacy_test_fun,class
rl::full_search_scheduler<3> >::fiber_proc_impl, context.hpp(457)
[7] 0: <0000022E2E81C890> exchange , prev=0, arg=1, new=1,
order=relaxed, in ct_alex_mutex_test_windows::lock, ct_main.cpp(32)
[8] 0: <0000022E2E81C870> load, value=0, in ct_relacy_test_fun::thread,
ct_main.cpp(78)
[9] 0: <0000022E2E81C870> store, value=1, in ct_relacy_test_fun::thread,
ct_main.cpp(78)
[10] 0: release fence, in ct_alex_mutex_test_windows::unlock,
ct_main.cpp(45)
[11] 0: <0000022E2E81C890> exchange , prev=1, arg=0, new=0,
order=relaxed, in ct_alex_mutex_test_windows::unlock, ct_main.cpp(47)
[12] 0: [THREAD FINISHED], in rl::context_impl<struct
ct_relacy_test_fun,class rl::full_search_scheduler<3>
>::fiber_proc_impl, context.hpp(457)
thread 1:
[13] 1: <0000022E2E81C890> exchange , prev=0, arg=1, new=1,
order=relaxed, in ct_alex_mutex_test_windows::lock, ct_main.cpp(32)
[14] 1: <0000022E2E81C870> load, value=0, in ct_relacy_test_fun::thread,
ct_main.cpp(78)
[15] 1: DATA RACE (data race detected), in ct_relacy_test_fun::thread,
ct_main.cpp(78)
thread 2:
_______________________________
Pretty good!
:^D