views:

58

answers:

3

Basically, it is used to make an application instance singleton.

I wish to know, how it works internally and how does OS manage it ?

+1  A: 

It creates a system-wide object. How the OS manages it is a consealed implementation detail, you can only use the mutex trough the OS-supplied functions (like ReleaseMutex() for example).

sharptooth
+1  A: 

This MSDN Article has some information about the underlying details of mutexes. In general, a mutex created with the Windows CreateMutex function is a kernel-owned object, which means that a user level application must transition from user mode to kernel mode to acquire ownership of the mutex.

Mark Wilkins
+1  A: 

This gives a few hints about internals

http://msdn.microsoft.com/en-us/library/ms684266%28VS.85%29.aspx

If you are interested in algorithms wikipedia is a good starting point. If you are interested in implementation, google linux source code semaphore.c

stacker