From: "Rob Fanner" <rfanner@stonethree.com>
To: "Bossom, John" <John.Bossom@Cognos.COM>,
<pthreads-win32@sources.redhat.com>
Subject: Re: semaphores
Date: Thu, 30 May 2002 09:33:00 -0000 [thread overview]
Message-ID: <010a01c207f7$85bb0ce0$0c01a8c0@thor> (raw)
In-Reply-To: <430F887D415DD1118C2700805F31ECF106B591B1@sota0005.cognos.com>
[-- Attachment #1: Type: text/plain, Size: 1390 bytes --]
Thanks for the advice. There is one error in the
original code frag, though:
(taken from the Linux threads man pages)
The sem_wait and sem_getvalue functions always return 0.
So, the assert() on sem_getvalue() should always have worked,
under the linux threads documentation.
pthreads-win32, however, seems to return -1 on failure (which
is ok for the code frag)
if ( result != 0 )
{
errno = result;
return -1;
}
However, this indicates that the sem_getvalue() implementation in pthreads-win32, or my compilation, is not quite as it should be.
Thanks to J Bossom for his suggestion. The following fragment
compiles and runs just fine:
#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);
// if the semaphore initialisation was ok, the sem
// should now have the value 10
// trying out J Bossom's idea of counting down
// using a trywait
int cnt=0;
while (sem_trywait(&psem)==0) cnt++;
cout << "Final value of cnt is " << cnt << endl << flush;
return 0;
}
This indicates that the sem_init() and sem_trywait(), functions
are OK.
[-- Attachment #2: Type: text/html, Size: 3143 bytes --]
next prev parent reply other threads:[~2002-05-30 16:33 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 ` Rob Fanner [this message]
2002-05-30 9:38 ` semaphores Rob Fanner
2002-05-30 22:32 ` semaphores Ross Johnson
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='010a01c207f7$85bb0ce0$0c01a8c0@thor' \
--to=rfanner@stonethree.com \
--cc=John.Bossom@Cognos.COM \
--cc=pthreads-win32@sources.redhat.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).