From: Patrick Frants <patrick@quintiq.com>
To: pthreads-win32@sourceware.cygnus.com
Subject: sem_trywait never returns EAGAIN
Date: Tue, 26 Feb 2002 09:41:00 -0000 [thread overview]
Message-ID: <DASNUS9686D9HE82IHGFDAIE65TQLJG.3c7bc907@PATRICK_DESKTOP> (raw)
Hi,
From the Linux man pages I concluded that calling sem_trywait on a semaphore with a zero count should result in an EAGAIN return value. I get a -1 all time
time. Intiializing the count with 1 and calling sem_trywait two times results in 0 and -1 return codes. Initializing with 0, calling sem_trywait results in a -1 return
code. Initializing with 0, calling sem_post, and sem_trywait twice results in 0 and -1 return codes for the sem_trywait calls.
Are my expectations wrong or is the behaviour of the library wrong?
Here is my sample code:
#include <pthread.h>
#include <semaphore.h>
#include <cassert>
#include <cstdio>
#pragma comment(lib, "pthreadvce")
int main(int argc, char** argv)
{
sem_t s;
assert(sem_init(&s, 0, 0) == 0);
int result = sem_trywait(&s);
if ( result == -1 )
{
perror("sem_wait"); // No error
}
else
{
printf("ok\n");
}
result = sem_post(&s);
result = sem_trywait(&s);
if ( result == -1 )
{
perror("sem_wait");
}
else
{
printf("ok\n");
}
return 0;
}
--
Patrick Frants
Senior Software Engineer
Quintiq
patrick@quintiq.com
www.quintiq.com
next reply other threads:[~2002-02-26 17:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-26 9:41 Patrick Frants [this message]
2002-02-26 9:52 Bossom, John
2002-02-26 10:04 Patrick Frants
2002-03-01 22:08 ` 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=DASNUS9686D9HE82IHGFDAIE65TQLJG.3c7bc907@PATRICK_DESKTOP \
--to=patrick@quintiq.com \
--cc=pthreads-win32@sourceware.cygnus.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).