Subj : Re: Can you limit the number of Posts to a POSIX semaphore? To : comp.programming.threads From : the_edge123.nospam Date : Wed Aug 10 2005 01:55 am Frank J. Lhota a =E9crit : > I'm looking into porting a Win32 program to Linux. This program makes > use of the fact that a Win32 semaphore is created with both an initial > value and a maximum value. For example, > > hSem =3D CreateSemaphore (NULL, 1, 3, NULL); > > creates a semaphore with an initial value of 1 and a maximum value of 3. > If ReleaseSemaphore (the Win32 version of sem_post) is called for hSem > when its value is already equal to 3, then ReleaseSemaphore fails with > an error code of ERROR_TOO_MANY_POSTS, and the value of hSem is not > incremented. > > Is there an easy way to do this with POSIX semaphores? AFAICT there is a > fairly large, system-wide upper limit on the value of a POSIX sem_t > value. What I am looking for is something that works like sem_t, except > that we can set an upper limit (other than SEM_VALUE_MAX) on the value > of the semaphore. >=20 > Any help would be most appreciated. >=20 You may use sem_getvalue... .