public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Vladimir Kliatchko <vladimir@kliatchko.com>
To: 'Gottlob Frege' <gottlobfrege@gmail.com>
Cc: 'Ross Johnson' <ross.johnson@homemail.com.au>,
	pthreads-win32@sources.redhat.com
Subject: RE: New pthread_once implementation
Date: Sat, 28 May 2005 01:30:00 -0000	[thread overview]
Message-ID: <0IH600AMQEVY5U@mta1.srv.hcvlny.cv.net> (raw)
In-Reply-To: <97ffb3105052709425ce1126a@mail.gmail.com>

Nice catch. Let me see if I can fix it.

Note that the same problem exists in the currently released event-based
implementation (cvs version 1.16):

thread1 comes in, start initing
thread2 creates event, starts waiting
thread3 comes in starts waiting
thread1 is cancelled, signals event
thread2 wakes up, proceeds to the point right before the resetEvent
thread3 wakes up, closes event handle 
thread2 resets closed handle

Re: you previous message:
>"If only one thread ever comes in, and is canceled in the init_routine, 
>then the semaphore is never cleaned up."

If only one thread ever comes in, and is canceled in the init_routine, then
the semaphore is never created to begin with, right?

Also, regarding my previous comment to Ross about very high cost of using
InterlockedExchangeAdd for MBR:
I did some simple benchmarking. Running pthread_once 50,000,000 on my pretty
slow single CPU machine takes about 2.1 seconds. Replacing
InterlockedExchangeAdd with simple read brings it down to 0.6 seconds. This
looks significant.

-----Original Message-----
From: Gottlob Frege [mailto:gottlobfrege@gmail.com] 
Sent: Friday, May 27, 2005 12:42 PM
To: Ross Johnson
Cc: Vladimir Kliatchko
Subject: Re: New pthread_once implementation

thread1 comes in, start initing
thread2 creates sema and waits
thread1 starts to cancel - resets control->state
thread3 comes in, goes into init
thread4 comes in, goes into else block
thread1 finishes cancel - releases semaphore
thread2 wakes up
thread2 decrements numSemaUsers to 0
thread4 increments numSemaUsers
thread4 does NOT set new semaphore
thread2 closes semaphore
thread4 tries to wait on closed semaphore...


On 5/27/05, Ross Johnson <ross.johnson@homemail.com.au> wrote:
> Guys,
> 
> Is there anything you want to change before I cast a new release?
> 
> http://sources.redhat.com/cgi-bin/cvsweb.cgi/pthreads/pthread_once.c?
> rev=1.18&content-type=text/x-cvsweb-markup&cvsroot=pthreads-win32
> 
> Thanks.
> Ross
> 
> On Fri, 2005-05-27 at 08:39 -0500, Tim Theisen wrote:
> > I picked up the latest and compiled with VC 7.1.  All tests passed.
> > Then, I ran 100 iterations of the once [1-4] tests.  These tests passed
> > as well.  So, it has my stamp of approval.
> >
> > ...Tim
> > --
> >        Tim Theisen                     Lead Research Software Engineer
> > Phone: +1 608 824 2848                 TomoTherapy Incorporated
> >   Fax: +1 608 824 2996                 1240 Deming Way
> >   Web: http://www.tomotherapy.com      Madison, WI 53717-1954
> >
> >
> >
> > -----Original Message-----
> > From: Ross Johnson [mailto:ross.johnson@homemail.com.au]
> > Sent: Friday, May 27, 2005 02:44
> > To: Tim Theisen
> > Cc: Vladimir Kliatchko; Gottlob Frege
> > Subject: New pthread_once implementation
> >
> >
> > Hi Tim,
> >
> > The current CVS head contains the latest and much simpler implementation
> > of pthread_once just presented on the mailing list. It passes on a UP
> > machine as usual but no-one has run it through an MP system yet. Could
> > you when you get time?
> >
> > Thanks.
> > Ross
> >
> >
> >
> 
>

       reply	other threads:[~2005-05-28  1:30 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 [this message]
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

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=0IH600AMQEVY5U@mta1.srv.hcvlny.cv.net \
    --to=vladimir@kliatchko.com \
    --cc=gottlobfrege@gmail.com \
    --cc=pthreads-win32@sources.redhat.com \
    --cc=ross.johnson@homemail.com.au \
    /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).