Subj : Re: Can you limit the number of Posts to a POSIX semaphore? To : comp.programming.threads From : Frank J. Lhota Date : Wed Aug 10 2005 02:36 pm the_edge123.nospam@club-internet.fr wrote: > Frank J. Lhota a écrit : > > >>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 = 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. >> >>Any help would be most appreciated. >> > > You may use sem_getvalue... I could, but it seems quite likely that I would introduce a race condition. -- "All things extant in this world, Gods of Heaven, gods of Earth, Let everything be as it should be; Thus shall it be!" - Magical chant from "Magical Shopping Arcade Abenobashi" "Drizzle, Drazzle, Drozzle, Drome, Time for the this one to come home!" - Mr. Lizard from "Tutor Turtle" .