abc
abc

Reputation: 11

A question on semaphore value if a process terminates abnormally after decrementing the semaphore value

if a process goes down after decrementing the value of semaphore from 1 to 0, as per my understanding the value of semaphore remains as 0.

If the same process comes up again and tries to re-acquire the same semaphore, it will block for ever.

Is there a way to reset the semaphore value to 1 after decrementing it if my process goes down abnormally?

Upvotes: 0

Views: 307

Answers (1)

Finslicer
Finslicer

Reputation: 878

I assume you are using the standard semctl()/semop() API for the semaphores.

There is a flag available called SEM_UNDO that will tell the kernel to reset the semaphore's value if your process terminates. You need to use this in your semop( ) calls.

More information here : http://beej.us/guide/bgipc/output/html/multipage/semaphores.html

Upvotes: 1

Related Questions