This is the mail archive of the 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]

SV: semaphores

	-----Ursprungligt meddelande-----
	Från:	Ross Johnson []
	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
	Here it comes:
	if (sem_init (&sem, 1 1) < 0) {
	      printf("sem_init. errno is %d\n",errno);
	      switch (errno) {
	         case EINVAL :
	            printf("value exceeds SEM_VALUE_MAX. \n");
	         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");
	         case ENOSYS :
	            printf(" sem_init() is not supported by this
implementation. \n");
	         case EPERM :
	            printf(" The calling process lacks the appropriate
privileges to initialize the semaphore. \n");



	Perhaps I've misunderstood the usage of sem_init. In a manpage I
read (
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
	> 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
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?

Michael Ambrus