LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Linux semaphore behaviod (https://www.linuxquestions.org/questions/linux-general-1/linux-semaphore-behaviod-590095/)

icarus127 10-07-2007 02:01 PM

Linux semaphore behavior
 
Hi all, I'm not sure where this should go. I didn't see a dedicated *nix system programming forum. If this is a bad place to put this could a mod please move it? :)

Anyhoo, my question. I'm working on an embedded linux system which will have multiple processes running and sharing memory. I've been looking at the semaphores in the sys/sem.h include and these seem fairly simple to use. The problem is that their behavior seems to be that if multiple processes are sleeping on a semaphore as soon as a process signals said semaphore ALL processes wake up and continue.

Obviously if I want to use these to protect a segment of shared memory I can't have that. What I need is a way to only wake up one process at a time(I don't care about order right now). I know that I could make a multi-semaphore array and have one semaphore per process but I would like to avoid this for the sake of portability and aesthetics.

Any suggestions? Thanks much :)

edit:
After doing some more testing it turns out that the semaphore only behaves this way if I have multiple copies of a given program waiting on it. If each program waiting on it has been recompiled with a different -o option the semaphore behaves as I expected. This will be sufficient for now but does anyone know a way around this? I can easily think of a case in which I want to run the same program multiple times using the same semaphores.
A producer consumer model for example in which all producers are identical and all consumers are identical for parallel processing in a genetic algorithm. Anyone have any suggestions to get around this? Thanks much.
Icarus


All times are GMT -5. The time now is 09:13 AM.