Every time I read the description of semget: The semget() system call returns the semaphore set identifier associated with the argument key.
, I wonder where do we really need set of System V Semaphores.
I always give the nsems
parameter as 1
because most of the times I require a single semaphore. Even if I don't need a binary semaphore why would I create a set of 5-6 semaphores (say).
and what if a process creates a set of 6 semaphores associated with a single key and another tries to do semget on the same key asking for just 3 semaphores. Also aren't all those 6 semaphores 6 individual binary semaphores. I am thirsty and looking for an answer to this question for 2 months (not continuously of-course).
I am sorry if this question seems to be the most stupid one but unless I get an example of the real use of the set of semaphores this doubt will remain in my mind. I have tried to search for an example C code where someone is using a set of semaphore but I could not find one.
I would be really really thankful to you guys if you could help me out on this. Thanks a tonne in advance.
I work on a DBMS that uses one semaphore for each of of a set of cooperating processes that work on the same data, cooperating via shared memory. Having to allocate those one at a time would be a nuisance; having a semaphore set with 20 (or whatever) semaphores in it is very convenient.