public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "Rob Fanner" <rfanner@stonethree.com>
To: "Ross Johnson" <rpj@ise.canberra.edu.au>,
	"Bossom, John" <John.Bossom@Cognos.COM>
Cc: <pthreads-win32@sources.redhat.com>
Subject: Re: semaphores
Date: Fri, 31 May 2002 00:48:00 -0000	[thread overview]
Message-ID: <003601c20877$51262520$0c01a8c0@thor> (raw)
In-Reply-To: <3CF70ACF.902@ise.canberra.edu.au>

Ross wrote:

> Hi John/Rob,
>
> Bossom, John wrote:
> > sem_getvalue()?
> >

> There's no test in the current test suite for this routine (will do
> though). And the routine would seem to need to be rewritten.
>
> Regards.
> Ross

Thanks Ross. I've thought of one or two workarounds (which mostly
involve using ReleaseSemaphore(semhandle,1,previouscount) followed by a
trywait to solve the NT problem of not being able
to do a ReleaseSemaphore with a 0 releasecount.

However, a more elegant solution --- closer to the original intent --- could
be to exploit the following, taken from "Win32 System Programming
Second Edition" by Johnson M Hart, chapter 9, page 256 :

"The release count must be greater than zero, but if it would cause the
semaphore count to exceed the maximum, the call will fail, returning FALSE,
and the count will remain unchanged.
Releasing a semaphore with a large count is a method used to obtain the
current count atomically (of course, another
thread might change the value immediately)."

So instead of

     if ( ReleaseSemaphore( (*sem)->sem, 0L, &value) )
        {
          *sval = value;
        }

this might be a good alternative

     if ( ReleaseSemaphore( (*sem)->sem, GREATER_THAN_MAXIMUM_SEM_VALUE,
&value) )
        {
          *sval = value;
        }

Sorry that I've not hacked this into the source and sent you a correct
patch, but I'm still not confident with VC++ builds, and
I'm still a bit clueless as to how to set up a pthreadVCE.lib (which I need)
as opposed to a pthreadVC.lib (the standard
build for the distro's .dsp file).

OK. Thanks again for all the advice. It is really appreciated.

Rob

  reply	other threads:[~2002-05-31  7:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-30  7:49 semaphores Bossom, John
2002-05-30  8:37 ` semaphores Phil Frisbie, Jr.
2002-05-30  9:33 ` semaphores Rob Fanner
2002-05-30  9:38 ` semaphores Rob Fanner
2002-05-30 22:32 ` semaphores Ross Johnson
2002-05-31  0:48   ` Rob Fanner [this message]
2002-06-02 21:35     ` semaphores Ross Johnson
  -- strict thread matches above, loose matches on Subject: below --
2002-06-05  4:25 Semaphores Platzer Wolfgang
2002-05-30  8:49 semaphores Nicolas EDEL
2002-05-30  7:11 semaphores Rob Fanner
1999-04-20 13:08 semaphores Michael Ambrus
1999-04-20 19:16 ` semaphores 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='003601c20877$51262520$0c01a8c0@thor' \
    --to=rfanner@stonethree.com \
    --cc=John.Bossom@Cognos.COM \
    --cc=pthreads-win32@sources.redhat.com \
    --cc=rpj@ise.canberra.edu.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).