Hello Alexander, On Sun, 18 Jun 2017 13:01:18 +0300 (MSK) Alexander Monakov wrote: > On Fri, 16 Jun 2017, Jens Gustedt wrote: > > void __lock(volatile int *l) > > { > > - if (libc.threads_minus_1) > > - while (a_swap(l, 1)) __wait(l, l+1, 1, 1); > > + /* This test is mostly useless, now. Leaving it to the > > first CAS is > > + probably just as efficient. */ > > + if (libc.threads_minus_1) { > [...] > > void __unlock(volatile int *l) > > { > > - if (l[0]) { > > - a_store(l, 0); > > - if (l[1]) __wake(l, 1, 1); > > + if (a_fetch_add(l, INT_MAX) != -INT_MAX) { > > + __syscall(SYS_futex, l, FUTEX_WAKE|FUTEX_PRIVATE, > > 1); } > > } > > This looks wrong in single-threaded case, __lock doesn't touch the > lock, but __unlock modifies it unconditionally. Right, probably there should be the same test as for the lock case. Or we should drop that test all along. I don't think that it still serves much purpose here. This is just trading one memory access against another. Thanks Jens -- :: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS ::: :: ::::::::::::::: office Strasbourg : +33 368854536 :: :: :::::::::::::::::::::: gsm France : +33 651400183 :: :: ::::::::::::::: gsm international : +49 15737185122 :: :: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::