Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 10-07-2007, 02:01 PM   #1
LQ Newbie
Registered: Aug 2007
Distribution: Slackware 12.2
Posts: 22

Rep: Reputation: 15
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

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.

Last edited by icarus127; 10-07-2007 at 08:59 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
semaphore beginner_84 Programming 5 08-25-2004 06:54 PM
Linux kernel module programming(Signal and semaphore) eshwar_ind Programming 1 02-16-2004 12:10 PM
about semaphore dummyagain Programming 1 11-11-2003 11:09 AM
how to use fork and semaphore in C/C++ in Linux? cs87668 Programming 1 06-20-2003 10:07 AM
semaphore init problem in linux marry_jeo Programming 0 02-25-2003 11:20 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:34 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration