From: Bruno Haible <bruno@clisp.org>
To: cygwin@cygwin.com, Takashi Yano <takashi.yano@nifty.ne.jp>
Subject: Re: [PATCH v2] Cygwin: pthread: Fix a race issue introduced by the commit 2c5433e5da82
Date: Thu, 30 May 2024 15:38:58 +0200 [thread overview]
Message-ID: <5687998.SimZDucyVS@nimes> (raw)
In-Reply-To: <20240530205918.7c730117b567bb3bec3a0c3f@nifty.ne.jp>
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
next prev parent reply other threads:[~2024-05-30 13:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240530050538.53724-1-takashi.yano@nifty.ne.jp>
[not found] ` <0126a98a-3bdc-4303-a0d2-09f4c7009392@gmail.com>
2024-05-30 8:47 ` Bruno Haible
2024-05-30 8:59 ` Noel Grandin
2024-05-30 9:15 ` Bruno Haible
2024-05-30 10:28 ` Noel Grandin
2024-05-30 13:53 ` SRW locks Bruno Haible
2024-05-30 10:14 ` [PATCH v2] Cygwin: pthread: Fix a race issue introduced by the commit 2c5433e5da82 Bruno Haible
[not found] ` <20240530205012.2aff4d507acac144e50df2a4@nifty.ne.jp>
[not found] ` <20240530205918.7c730117b567bb3bec3a0c3f@nifty.ne.jp>
2024-05-30 13:38 ` Bruno Haible [this message]
2024-05-31 14:01 ` Bruno Haible
2024-06-01 14:18 ` Takashi Yano
2024-06-01 16:08 ` Ken Brown
2024-06-01 21:11 ` Takashi Yano
2024-06-02 13:14 ` Bruno Haible
2024-06-02 14:27 ` Takashi Yano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5687998.SimZDucyVS@nimes \
--to=bruno@clisp.org \
--cc=cygwin@cygwin.com \
--cc=takashi.yano@nifty.ne.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).