mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-05 12:12:28 +00:00
Fix ordering of pthread_create(pthread_t *thread)
This change fixes a bug where signal_latency_async_test would flake less than 1/1000 of the time. What was happening was pthread_kill(sender_thr) would return EFAULT. This was because pthread_create() was not returning the thread object pointer until after clone() had been called. So it was actually possible for the main thread to stall after calling clone() and during that time the receiver would launch and receive a signal from the sender thread, and then fail when it tried to send a pong. I thought I'd use a barrier at first, in the test, to synchronize thread creation, but I firmly believe that pthread_create() was to blame and now that's fixed
This commit is contained in:
parent
ed6d133a27
commit
e939659b70
6 changed files with 57 additions and 63 deletions
|
@ -128,7 +128,7 @@ forceinline pureconst struct PosixThread *_pthread_self(void) {
|
|||
}
|
||||
|
||||
forceinline void _pthread_ref(struct PosixThread *pt) {
|
||||
atomic_fetch_add_explicit(&pt->pt_refs, 1, memory_order_acq_rel);
|
||||
atomic_fetch_add_explicit(&pt->pt_refs, 1, memory_order_relaxed);
|
||||
}
|
||||
|
||||
forceinline void _pthread_unref(struct PosixThread *pt) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue