[Mono-list] Named Mutex on Linux

Dick Porter dick at ximian.com
Mon Jan 30 09:15:00 EST 2006


On Thu, 2006-01-26 at 08:37 -0600, jeff clausius wrote:
> I have a user who says a system named mutex is not being released on
> RedHat Enterprise Linux v3 using Mono 1.1.12.1.  I don't have any
> particulars yet about how this is happening, so I'm trying to form a
> theory on why this is happening.
> 
> I've examined the code, and I don't think it is a bug in there.  The
> release of the mutex is found in a try/finally, so if the console
> encounters an exception, it is guaranteed the mutex would be released.
> 
> 
> Is it possible if a console app is killed while owning a system wide
> named mutex that the mutex is not released?  (I wonder if that is what
> is happening in my reported case - Ctrl-C while owning the mutex.)

I don't see any SIGTERM handlers in the runtime, so I doubt finally
blocks will be executed if you hit C-c.

> On a different note, I'm looking for a way to release system wide
> mutexes.  If I encounter a situation where a named mutex is in a "hanged
> state" is there a way to release it?  I thought I read Mono used a
> daemon to handle system wide mutexes?  If so, what is the name of that
> daemon?  Would restarting it release the mutex?  Are there other options
> here?

There used to be a daemon managing shared handles, but we removed that.
These days, named mutexes are released by a mono process when it exits
normally.  If a process crashes or is killed it will leave named mutexes
locked, but a new process will clean up the old named mutex when it
tries to open it again (there is a 60 second window where the old named
mutex will still be considered "alive" though.)

I've just realised there is a bug here, in that if a process is already
waiting for the named mutex when the process holding it terminates
prematurely, then the wait will not finish.  I'll look at that now.

- Dick




More information about the Mono-list mailing list