Basically, it is used to make an application instance singleton.
I wish to 开发者_Go百科know, how it works internally and how does OS manage it ?
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).
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.
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
精彩评论