To verify the code I'm checking it with Relacy race detector. Here it is:
1. Even though test passes and relacy does not give any warnings, the same test w/o relacy-related stuff will occasionally fail on this assertion:
Could anyone please comment on the algorithm in general, and on memory-orderings in particular? Whenever I change all memory orders to seq_cst, I see 20x performance degradation, but see no errors (although they might just have become rarer).
2. If I compile with -O1 or higher, program crashes:
Stack trace:
#0 0x00007ffff74be0d5 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00007ffff74c183b in __GI_abort () at abort.c:91
#2 0x00007ffff74fb32e in __libc_message (do_abort=2, fmt=0x7ffff7603412 "*** %s ***: %s terminated\n")
at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
#3 0x00007ffff7591e57 in __GI___fortify_fail (msg=0x7ffff76033d1 "longjmp causes uninitialized stack frame") at fortify_fail.c:32
#4 0x00007ffff7591dcd in ____longjmp_chk () at ../sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S:90
#5 0x00007ffff7591d33 in __longjmp_chk (env=0x7fffffffd928, val=<optimized out>) at ../setjmp/longjmp.c:40
#6 0x0000000000405daf in switch_to_fiber(fiber_t&, fiber_t&) () at relacy_2_4/relacy/platform.hpp:223
#7 0x000000000040f02a in rl::test_result_e rl::run_test<smrp_test::race_test, rl::random_scheduler<2> >(rl::test_params&, std::ostream&, bool) () at relacy_2_4/relacy/context.hpp:703
#8 0x0000000000410e65 in bool rl::simulate<smrp_test::race_test>(rl::test_params&) () at relacy_2_4/relacy/context.hpp:960
#9 0x00000000004112df in bool rl::simulate<smrp_test::race_test>() () at relacy_2_4/relacy/context.hpp:1014
#10 0x0000000000402658 in main () at smrp_test.cpp:247