Sunday, 15 July 2012

semaphore - Different uses of the value parameter in sem_init(...) in c -


Suppose I initialize a semaphore in two different ways

  1. < Code> sem_init (& randommem, 0,1)
  2. sem_init (& randomsem, 0,0)

Now,

or

will it work for only

sem_wait (& randomsem) Work in both cases

sem_init (& amp; randomsem, 0,1) , using sem_wait (& amp; randomsem) As decreases the value parameter when it more than 0 and so if I Ndera the sem_init (& randomsem, 0,0) ??

, then this will not work? Please help!

  int sem_init (sem_t * sem, int pshared, unsigned int value);  

sem_init indicates by semaphore object end. The number associated with the semaphore is initially set to the value Pshared logic indicates that the sequor is current to the current process (pshared is zero) or to be shared between multiple processes (pshared is not zero).

The third parameter sets the value, the initial value of the semaphore, then in the first case your semaphore starts with the value of 1, the second cast 0;


No comments:

Post a Comment