[PATCH v2] Cygwin: pthread: Fix a race issue introduced by the commit 2c5433e5da82
Bruno Haible
bruno@clisp.org
Thu May 30 13:38:58 GMT 2024
Takashi Yano wrote in cygwin-patches:
> With v3 patch:
> int
> pthread::once (pthread_once_t *once_control, void (*init_routine) (void))
> {
> /* Sign bit of once_control->state is used as done flag */
> if (once_control->state & INT_MIN)
> return 0;
>
> /* The type of &once_control->state is int *, which is compatible with
> LONG * (the type of the first argument of InterlockedIncrement()). */
> InterlockedIncrement (&once_control->state);
> pthread_mutex_lock (&once_control->mutex);
> if (!(once_control->state & INT_MIN))
> {
> init_routine ();
> InterlockedOr (&once_control->state, INT_MIN);
> }
> pthread_mutex_unlock (&once_control->mutex);
> if (InterlockedDecrement (&once_control->state) == INT_MIN)
> pthread_mutex_destroy (&once_control->mutex);
> return 0;
> }
Looks good to me.
If it passes 10 or 100 runs of my test program from
<https://cygwin.com/pipermail/cygwin/2024-May/255987.html>,
I would say, it's good.
Thanks!
Bruno
More information about the Cygwin
mailing list