pthread_barrier_wait hangs with NPTL
Sebastien Decugis
sebastien.decugis@ext.bull.net
Wed Feb 18 10:59:00 GMT 2004
I have also a hang case with NPTL and not with Linuxthreads, with
barriers. It happens at least on i686 and ia64.
This happens with the following sequence:
-----------------
thread_A:
pthread_barrier_init(&b, NULL, 2)
pthread_create(pth, NULL, thread_B, NULL);
pthread_barrier_wait(&b);
pthread_barrier_destroy(&b);
pthread_barrier_init(&b, NULL, 3);
...
thread_B:
pthread_barrier_wait(&b); /* this function never returns with NPTL */
------------------
I have a complete example if someone wants to try it.
After some researchs, it appeared to me that the pthread_barrier_destroy
can return with success error code, while the other threads still need
to read data from the barrier (namely, the curr_event field).
This case happens because:
* thread_A inits the barrier, then enters pthread_create.
* thread_B starts running, and stops in FUTEX_WAIT inside
pthread_barrier_wait.
* thread_A resumes, in enters pthread_barrier_wait, calls FUTEX_WAKE,
but at this point on a uniprocessor, thread_B 'can' resume execution but
in fact thread_A goes on. It leaves pthread_barrier_wait and enters
pthread_barrier_destroy, which succeeds as the barrier seems to be not
used. The the thread_A can dispose of memory used by the barrier, as the
destroy call was successfull. Here we only reinitialize it.
* thread_B resumes, the futex was awaken so it tests for the CURR_EVENT
value, which is garbage, so it can loop and re-enter FUTEX_WAIT. The
thread hangs.
I attached to this email a proposal for a patch I wrote, but this is
incomplete since I only take care of i486 arch. Basically, it consists
of adding another field saying 'busy' in the pthread_barrier_t data.
NOTE: I previously posted this mail on the phil-list mailing list but
got no answer at all...
--
Sébastien DECUGIS
Bull S.A.
Tel: 04 76 29 74 93
-------------- next part --------------
A non-text attachment was scrubbed...
Name: barriers_hang_patch.patch
Type: text/x-patch
Size: 4903 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20040218/13eb44f8/attachment.bin>
More information about the Libc-alpha
mailing list