Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Relacy Rocks...

68 views
Skip to first unread message

Chris M. Thomasson

unread,
Nov 9, 2023, 3:13:16 AM11/9/23
to
Fwiw, I needed to get back into Relacy. Wrt Bonita, here is a Relacy
test unit for an old acquaintance of mine, Alex from over on
comp.programming.threads many years ago. A test of one of his fast
mutexes for windows, the code is used in:

Take notice that Relacy can model windows sync primitives, and C++...

rl::rl_HANDLE, rl_CreateEvent, ect, and such... ;^)


https://github.com/dvyukov/relacy

Just a quick test of Alex's original code:
______________________________________
#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
{
rl::rl_HANDLE m_waitset;
rl::atomic<unsigned long> m_state;

ct_alex_mutex_test_windows()
: m_waitset(rl_CreateEvent(nullptr, false, false, nullptr)),
m_state(0)
{
if (! m_waitset) throw;
}

~ct_alex_mutex_test_windows()
{
CloseHandle(m_waitset);
}

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, $);
}

void unlock()
{
rl::atomic_thread_fence(rl::mo_release, $);

if (m_state.exchange(0, rl::mo_relaxed, $) == 2)
{
rl_SetEvent(m_waitset, $);
}
}
};


struct ct_relacy_test_fun : rl::test_suite<ct_relacy_test_fun, CT_THREAD_N>
{
VAR_T(unsigned long) m_test_0;
ct_alex_mutex_test_windows m_mutex;


void before()
{
VAR(m_test_0) = 0;

//std::cout << "ct_relacy_test_fun::before()" << std::endl;
}

void after()
{
// std::cout << "ct_relacy_test_fun::after()" << std::endl;

RL_ASSERT(VAR(m_test_0) == CT_THREAD_N);
}

void thread(unsigned int tidx)
{
m_mutex.lock();
VAR(m_test_0) += 1;
m_mutex.unlock();
}
};


int
main()
{
std::cout << "Relacy Testing 123... ;^)" << std::endl;

{
rl::test_params p;

//p.iteration_count = 10000000;
//p.execution_depth_limit = 33333;
//p.search_type = rl::sched_bound;
p.search_type = rl::fair_full_search_scheduler_type;
//p.search_type = rl::fair_context_bound_scheduler_type;

rl::simulate<ct_relacy_test_fun>(p);
}

return 0;
}
______________________________________

My output:
______________________________________
Relacy Testing 123... ;^)
struct ct_relacy_test_fun
5% (65536/1129586)
iterations: 90732
total time: 1609
throughput: 56390
______________________________________

Nice! Working like a charm. Now I can get into playing around with my
new'ish queue algorithm. I basically need to distribute it.

Chris M. Thomasson

unread,
Nov 9, 2023, 3:16:43 AM11/9/23
to
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

Chris M. Thomasson

unread,
Nov 9, 2023, 3:18:16 AM11/9/23
to
On 11/9/2023 12:12 AM, Chris M. Thomasson wrote:
> Fwiw, I needed to get back into Relacy. Wrt Bonita, here is a Relacy
> test unit for an old acquaintance of mine, Alex from over on
> comp.programming.threads many years ago. A test of one of his fast
> mutexes for windows, the code is used in:
[...]

https://sourceware.org/pthreads-win32/

Chris M. Thomasson

unread,
Nov 9, 2023, 3:59:55 AM11/9/23
to
On 11/9/2023 12:12 AM, Chris M. Thomasson wrote:
> Fwiw, I needed to get back into Relacy. Wrt Bonita, here is a Relacy
> test unit for an old acquaintance of mine, Alex from over on
> comp.programming.threads many years ago. A test of one of his fast
> mutexes for windows, the code is used in:
>
> Take notice that Relacy can model windows sync primitives, and C++...
>
> rl::rl_HANDLE, rl_CreateEvent, ect, and such... ;^)
>
>
> https://github.com/dvyukov/relacy
>
> Just a quick test of Alex's original code:
[...]

Some music that reminds of Relacy processing a long test:

https://youtu.be/QQ77ejz6i4M

Chris M. Thomasson

unread,
Nov 10, 2023, 3:44:22 PM11/10/23
to
On 11/9/2023 12:12 AM, Chris M. Thomasson wrote:
> Fwiw, I needed to get back into Relacy. Wrt Bonita, here is a Relacy
> test unit for an old acquaintance of mine, Alex from over on
> comp.programming.threads many years ago. A test of one of his fast
> mutexes for windows, the code is used in:
>
> Take notice that Relacy can model windows sync primitives, and C++...
>
> rl::rl_HANDLE, rl_CreateEvent, ect, and such... ;^)
>
>
> https://github.com/dvyukov/relacy
[...]

Fwiw, you do not need to have windows installed to play around with
Relacy. It simulates windows primitives, and even PThread primitives.

Chris M. Thomasson

unread,
Nov 17, 2023, 2:32:29 AM11/17/23
to
On 11/9/2023 12:12 AM, Chris M. Thomasson wrote:
[...]

Almost ready to start work on my new queue. I have my plotter ready, and
it does create volumetric images of some of my experimental fractals. A
low res example at 256^3 volume:

https://i.ibb.co/8XfnmrR/image.png
0 new messages