i386: Use pthread_barrier for synchronization on tst-bz21269
authorDJ Delorie <dj@redhat.com>
Tue, 16 May 2023 02:50:35 +0000 (22:50 -0400)
committerDJ Delorie <dj@redhat.com>
Tue, 16 May 2023 19:09:18 +0000 (15:09 -0400)
commit088136aa02de6fa13061ef6f754071a5652fdabd
tree0ae9a5cf6eb6f5dff00ff0de893dd00a75bf4447
parentd877b52d58b1c73810751bdb48987b84bda87d5e
i386: Use pthread_barrier for synchronization on tst-bz21269

So I was able to reproduce the hangs in the original source, and debug
it, and fix it.  In doing so, I realized that we can't use anything
complex to trigger the thread because that "anything" might also cause
the expected segfault and force everything out of sync again.

Here's what I ended up with, and it doesn't seem to hang where the
original one hung quite often (in a tight while..end loop).  The key
changes are:

1. Calls to futex are error checked, with retries, to ensure that the
   futexes are actually doing what they're supposed to be doing.  In the
   original code, nearly every futex call returned an error.

2. The main loop has checks for whether the thread ran or not, and
   "unlocks" the thread if it didn't (this is how the original source
   hangs).

Note: the usleep() is not for timing purposes, but just to give the
kernel an excuse to run the other thread at that time.  The test will
not hang without it, but is more likely to test the right bugfix
if the usleep() is present.
sysdeps/unix/sysv/linux/i386/tst-bz21269.c