initialization of global semaphore (System V)
initialization of global semaphore (System V)
- Subject: initialization of global semaphore (System V)
- From: Alex Sheh <email@hidden>
- Date: Tue, 24 Nov 2009 11:56:16 -0800
- Acceptlanguage: en-US
- Thread-topic: initialization of global semaphore (System V)
Hi,
What is the standard way to initialize a global
semaphore (System V) on MacOSX?
I’m using a System V semaphore, because the
SEM_UNDO flag is available, which is useful for "undoing" an acquired resource.
So if a process acquires a resource and then crashes prior to releasing the
resource, the SEM_UNDO behavior will kindly release the resource for the
process.
Since the single resource will only be used by 1
client at a time, I want the global semaphore to be initiazed to 1, however I’m
not sure where to initialize it..
I could use semctl(…, SETVAL), and initializing it
in the first process that tries to acquire the global semaphore. However, the
Richard Stevens book says that the semaphore adjustment for semctl(…,SETVAL) is
to clear the semaphore value to 0. This means that if Process 1 sets the global
semaphore to 1, and then crashes, this will leave the global semaphore at 0.
Then when Process 2 tries to acquire the global semaphore, it will never be able
to, because the value will remain at 0.
Is it better to schedule a daemon whose sole
function is to set the global semaphore to 1 and remain running? And then if
this daemon ever crashes and adjusts the value to 0, for the daemon to be restarted, which will then
re-initialize the global semaphore
value to 1 (making it available again)?
Thanks for your help.
Best,
Alex
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden