This is the mail archive of the pthreads-win32@sourceware.cygnus.com mailing list for the pthreads-win32 project. See the pthreads-win32 home page for more information.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
-----Ursprungligt meddelande-----
Från: Ross Johnson [SMTP:rpj@ise.canberra.edu.au]
Skickat: den 21 april 1999 04:16
Till: Michael Ambrus
Kopia: 'pthreads-win32 mailing list'
Ämne: Re: semaphores
On Tue, 20 Apr 1999, Michael Ambrus wrote:
> Hi,
> I've tried the new semaphores and they seem to work fine except
that errno
> is not properly set as Ross said.
Are you using the 1999-04-07 snapshot? Anything before that should
be upgraded.
Yes I am.
Can you provide me with some code that illustrates the
problem?
Here it comes:
if (sem_init (&sem, 1 1) < 0) {
perror("sem_init");
printf("sem_init. errno is %d\n",errno);
switch (errno) {
case EINVAL :
printf("value exceeds SEM_VALUE_MAX. \n");
break;
case ENOSPC :
printf(" A resource required to initialize the semaphore
has been exhausted.\n
The resources have reached the limit on
semaphores, SEM_NSEMS_MAX. \n");
break;
case ENOSYS :
printf(" sem_init() is not supported by this
implementation. \n");
break;
case EPERM :
printf(" The calling process lacks the appropriate
privileges to initialize the semaphore. \n");
break;
}
scanf("%c",c);
exit(1);
}
Perhaps I've misunderstood the usage of sem_init. In a manpage I
read (
http://www.doc.ic.ac.uk/~mac/manuals/solaris-manual-pages/solaris/usr/man/ma
n3r/sem_init.3r.html
<http://www.doc.ic.ac.uk/~mac/manuals/solaris-manual-pages/solaris/usr/man/m
an3r/sem_init.3r.html> ) sem_init should return a value < 0 if an error
occurred and errno should be set with the corresponding error.
The simple test I wrote (tests/errno1.c in the source tree)
checks that two threads can set and retrieve values of errno
independently. The test succeeds for MSVC (tested on WinNT) and
Mingw32 (tested on Win98).
I used cygwin GCC B20.1 ...
> I'm confused about the "pshared" attribute
> though. Should it not be != 0 if the semaphore is to be shared
between
> processes/treads ?
pshared should be non-zero for shared semaphores, however,
pthreads-win32 doesn't yet support any process shared objects. So
sem_init should return EPERM if you set pshared != 0.
Some other thoughts..
* pthread_delay_np ( se
http://www-server.rcnp.osaka-u.ac.jp/unix/DOCUMENTATION/HTML/AA-Q2DPC-TKT1_h
tml/thrd0384.html
<http://www-server.rcnp.osaka-u.ac.jp/unix/DOCUMENTATION/HTML/AA-Q2DPC-TKT1_
html/thrd0384.html> ) would be nice. Is anyone working on it?
* What happens if sleep() is used? Is the whole process suspended, or
does other threads run?
* POSIX queues would be nice. Is it possible to implement them with
POSIX 1003.1a semaphores?
W.k.r.
Michael Ambrus