public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Ross Johnson <rpj@ise.canberra.edu.au>
To: "Bossom, John" <John.Bossom@Cognos.COM>
Cc: "'Rob Fanner'" <rfanner@stonethree.com>,
	pthreads-win32@sources.redhat.com
Subject: Re: semaphores
Date: Thu, 30 May 2002 22:32:00 -0000	[thread overview]
Message-ID: <3CF70ACF.902@ise.canberra.edu.au> (raw)
In-Reply-To: <430F887D415DD1118C2700805F31ECF106B591B1@sota0005.cognos.com>

Hi John/Rob,

Bossom, John wrote:
> sem_getvalue()?
> 
> I don't see that in the standard (POSIX.1b (POSIX 1003.1b-1993))... I 
> assume this has been added to the pthreads-win32 implementation
 > as an extension (Ross?)

This function is noted by the contributor in the ChangeLog as a 
'trial' version. It appears to be defined according to the Single 
Unix Specification version 2 (as noted by other respondents):-

http://www.opengroup.org/onlinepubs/7908799/xsh/sem_getvalue.html

This definition is different to the latest POSIX standard IEEE Std 
1003.1-200x (I'm looking at draft 7), which removes ENOSYS from the 
list of returnable errors for this function. I don't know if that 
means that it must not return ENOSYS.

> 
> Perhaps there is a bug in that new method.
> 

The following comment and code is pretty much all there is to the 
function:

/* Note:
  *  The windows NT documentation says that the increment must be
  *  greater than zero, but it is set to zero here. If this works,
  *  the function will return true. If not, we can't do it this way
  *  so flag it as not implemented.
  */
       if ( ReleaseSemaphore( (*sem)->sem, 0L, &value) )
         {
           *sval = value;
         }
       else
         {
           result = ENOSYS;
         }

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

>  
> 
> However, try looping over sem_trywait and count the # of times it 
> returns 0. It should return EAGAIN
> 
> when the semaphore count is zero.
> 
>  
> 
> Sorry, I can't help you with the sem_getvalue....
> 
>  
> 
> Note that since the sem_ calls are from an earlier standard, that when 
> they fail they are supposed
> 
> to return -1 and set errno to the actual error number....
> 
>  
> 
> John.
> 
>     -----Original Message-----
>     *From:* Rob Fanner [mailto:rfanner@stonethree.com]
>     *Sent:* May 30, 2002 10:10 AM
>     *To:* pthreads-win32@sources.redhat.com
>     *Subject:* semaphores
> 
>     I'm new to using pthreads-win32 (SNAPSHOT 2002-03-02), and I have to
>     port 
> 
>     a program from Linux to Windows 2000. A bug has somehow crept into my
> 
>     code, and I've narrowed the problem area down to a code fragment
>     similar
> 
>     to the following:
> 
>      
> 
>     #include <semaphore.h>
>     #include <cassert>
>     #include <iostream>
> 
>      
> 
>     using namespace std;
> 
>      
> 
>     int main()
>     {
>        /**
>         * We want to check wether a semaphore can be initialised
>         * with a value.
>         */
>       
>        // a semaphore
>        sem_t psem;
> 
>      
> 
>        // initialise it with value 10
>        assert(sem_init(&psem,0,10) == 0);                       //
>     ASSERT NO 1
>        // if the semaphore initialisation was ok, the sem
>        // should now have the value 10
>        int ret = 0;
>        assert(sem_getvalue(&psem,&ret) == 0);               // ASSERT NO 2
>        // if no errors occured then value is now in the
>        // integer ret
>        cout << endl << "sem_getvalue() returns value " << ret << endl <<
>     flush;
>      
>        return 0;
>     }
> 
>      
> 
>     I'm using MS VC++ 6.0, and I'm linking with the precompiled
>     pthreadVCE.lib library.
> 
>     At runtime, the first assert() passes OK, but second fails.
> 
>     I have no idea why this fails (hopefully it's simply a newby error,
>     and not a bug in
> 
>     the pthreads-win32 lib), but it does.
> 
>      
> 
>     Thanks
> 
>     Rob
> 
> 
> This message may contain privileged and/or confidential information. If 
> you have received this e-mail in error or are not the intended 
> recipient, you may not use, copy, disseminate or distribute it; do not 
> open any attachments, delete it immediately from your system and notify 
> the sender promptly by e-mail that you have done so. Thank you.
> 


-- 
+-------------------------+---+
| Ross Johnson            |   | "Come down off the cross
| Management & Technology |___|  We can use the wood" - Tom Waits
| Building 11                 |
| University of Canberra      | eMail: rpj@ise.canberra.edu.au
| ACT    2601                 | WWW: 
http://public.ise.canberra.edu.au/~rpj/
| AUSTRALIA                   |
+-----------------------------+

  parent reply	other threads:[~2002-05-31  5:32 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 ` Ross Johnson [this message]
2002-05-31  0:48   ` semaphores Rob Fanner
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=3CF70ACF.902@ise.canberra.edu.au \
    --to=rpj@ise.canberra.edu.au \
    --cc=John.Bossom@Cognos.COM \
    --cc=pthreads-win32@sources.redhat.com \
    --cc=rfanner@stonethree.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).