correction sem_get_value return a negative number if the semaphore is blocked. therefor while((sem_get_value(semaphore)) != 0) shuold be shifted with while((sem_get_value(semaphore)) < 0)
Semaphores is part of POSIX.1b which is the one that is implemented in RTLinux. (well, I am not sure that all semaphore funktions is implemented). Binary semaphores are NOT! But you could create one... 1) init a semaphore with the value 1. make a funktion sem_bin_wait and sem_bin_post. int sem_bin_wait(sem_t *semaphore) { int ret; ret = sem_wait(semaphore); if (ret==0) { while((sem_get_value(semaphore)) != 0) { ret = sem_wait(semaphore); } } return ret; } int sem_bin_post(sem_t *semaphore) { while(sem_get_value(semaphore) != 0) { sem_wait(semaphore); } return sema_post(semaphore); } I think it is pretty straigt. The funktions have not been tested!!!! but have just been made straigt from my mind. All the funktions does is to make sure that the semaphore have the correct value before continue. I also think that a test should be added to asure that the semphore is ok. Other funktions could be made the same way. Hope you can use it. Anders Gnistrup On Thu, 31 Jan 2002 09:17:28 +0100 Massimiliano Cialdi <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > > On Wed, Jan 30, 2002 at 11:12:20AM -0500, Ish Rattan wrote: > > > >>On Wed, 30 Jan 2002, Massimiliano Cialdi wrote: > > >>> > > >>>I need to use binary semaphore instead of counting. > >>>There is a posix implementation? > >>> > >>What about counting semaphore initalized to 1? > > Or mutex. > > > Anders Gnistrup wrote: > > > jep. ->Mutex. Mutex perform just like a binary semaphore. Mutex's is part of >pthread.h > > > > > mutexes depends on which thread locks them. > > > I need something like VxWorks binary semaphores which use semBcreate, > semaTake and semGive > > > > thanks > -- > Massimiliano Cialdi > [EMAIL PROTECTED] > [EMAIL PROTECTED] > > -- [rtl] --- To unsubscribe: echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED] -- For more information on Real-Time Linux see: http://www.rtlinux.org/