If this fails, read pid from existing Semaphore?, check if that pid exists, if not, then atomically unlink it and try the later statement again? That atomic part is what I am wondering about, how do we atomically unlink it and run the above statement at the same time?
For example:
Process1,
* Try above statement, fail
* Read semaphore pid and find process dead/gone that owned it.
* Sleep for 3 seconds (or > 3...)
* Unlink *wrong* semaphore, try the above statement again, succeed.
Process2,
* Try above statement, fail
* Read semaphore pid and find process dead/gone that owned it.
* Unlink *right* semaphore, try the above statement again, succeed.
Getting closer I think, the algorithm could be,
Try to run the following:
posix_ipc. Semaphore( "xyz002" ,flags= posix_ipc. O_CREAT, initial_ value=os. getpid( ))
If this fails, read pid from existing Semaphore?, check if that pid exists, if not, then atomically unlink it and try the later statement again? That atomic part is what I am wondering about, how do we atomically unlink it and run the above statement at the same time?
For example:
Process1,
* Try above statement, fail
* Read semaphore pid and find process dead/gone that owned it.
* Sleep for 3 seconds (or > 3...)
* Unlink *wrong* semaphore, try the above statement again, succeed.
Process2,
* Try above statement, fail
* Read semaphore pid and find process dead/gone that owned it.
* Unlink *right* semaphore, try the above statement again, succeed.