Sys V SEM_UNDO equivalent for positive semaphores

On a Linux system with multiple processes, the semaphore system V allows the use of SEM_UNDO, preventing the semaphore from β€œgetting stuck” if the process associated with the semaphore fails. What is the correct method to prevent POSIX semaphores from jamming as a result of a failure during semaphore storage? Or does POSIX guarantee that the semaphore is freed in the event of a failure?

+6
source share
1 answer

You can use the signal handler for SIGSEGV, and then unlock and remove the signal handler.

// set handler signal(SIGSEGV, handler); void handler(int signum) { // unlock the locked semaphores signal(SIGSEGV, SIG_DFL); } 
-1
source

Source: https://habr.com/ru/post/981341/


All Articles