Re: Semaphore Usage Problem
Nelson Bolyard <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Message-ID | <[email protected]> |
[email protected] wrote, On 2008-03-04 05:05: > I am using PRSem for managing various resources in my application. > > As these semaphores has kernel persistence, I run into a problem now > and then. > > If my program terminates abruptly, the next time I start the program, > it may wait forever on one of the semaphores > created by previous execution which had been terminated abruptly. > > My question is how can I recover from this without restarting the > system. Is there any strategy to use semaphores? > > One answer can be: Dont terminate program abruptly. > But I have to sometime. If I am debugging or doing something, I do > terminate. > More over, If my program crashes due to some coding error, the user > may not want to restart the whole system. IMO, NSPR does not offer a good cross-platform solution to that problem. NSS's libSSL has come up with its own solution to that, but it may not meet your requirements exactly. It uses pipes on systems that don't release semaphores when the owner dies. You might look at http://lxr.mozilla.org/security/source/security/nss/lib/ssl/sslmutex.h#40 http://lxr.mozilla.org/security/source/security/nss/lib/ssl/sslmutex.c#92 http://lxr.mozilla.org/security/source/security/nss/lib/ssl/sslmutex.c#264