public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Ross Johnson <rpj@callisto.canberra.edu.au>
To: Gottlob Frege <gottlobfrege@gmail.com>
Cc: Vladimir Kliatchko <vladimir@kliatchko.com>,
	Pthreads-Win32 list <pthreads-win32@sources.redhat.com>
Subject: Re: New pthread_once implementation
Date: Wed, 01 Jun 2005 03:02:00 -0000	[thread overview]
Message-ID: <1117594912.6822.67.camel@desk.home> (raw)
In-Reply-To: <97ffb3105053109285d5660ad@mail.gmail.com>

On Tue, 2005-05-31 at 12:28 -0400, Gottlob Frege wrote:
> I think that might be reasonable.
> 
> Here's another tact we could try:
> 
> In the case of cancel, release the semaphore BUT do NOT reset the
> control state.  In the waiting case, after waiting, check if state ==
> done.  If not done, we know something went wrong - fall back to using
> a named mutex.  Note that ALL new threads coming in will go to the
> wait case then into the namedmutex code - after a cancel, no threads
> try to call init in the normal way.
> 
> Does that make sense?

The cancellation handler must change 'state' before checking for the
semaphore, otherwise there's no possibility of managing the race between
the cancelled thread and a thread that has just entered the wait track
but not yet created the semaphore. That waiter will be stranded until a
new thread comes by.

The form of pthread_once with the MCS queue-based lock is the same as
that proposed by Alexander. Vlad's MCS lock implementation is the
missing element: it is light-weight in the uncontended case; is
efficient otherwise (including attempting to minimise cache-coherence
operations on MP systems), and; can be incorporated without changing the
library's ABI. I think it deserves inclusion in the next release.

If there are refinements that can be made to pthread_once later then
they can be considered, but in the meantime we will have a fully
working, robust, and efficient pthread_once.

Ross


      reply	other threads:[~2005-06-01  3:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <97ffb3105052709425ce1126a@mail.gmail.com>
2005-05-28  1:30 ` Vladimir Kliatchko
2005-05-28  3:46   ` Ross Johnson
2005-05-28 10:51     ` Vladimir Kliatchko
2005-05-28 13:54       ` Ross Johnson
2005-05-28 14:29         ` Vladimir Kliatchko
2005-05-29 12:58           ` Vladimir Kliatchko
2005-05-30 14:48           ` Ross Johnson
2005-05-30 15:26             ` Vladimir Kliatchko
2005-05-31 16:28               ` Gottlob Frege
2005-06-01  3:02                 ` Ross Johnson [this message]

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=1117594912.6822.67.camel@desk.home \
    --to=rpj@callisto.canberra.edu.au \
    --cc=gottlobfrege@gmail.com \
    --cc=pthreads-win32@sources.redhat.com \
    --cc=vladimir@kliatchko.com \
    /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).