1

Topic: CloseHandle () does not remove lock named

Came across on interesting  : if to block  and to make CloseHandle () that it will not be unblocked before process end.

#include <windows.h>
#include <stdio.h>
int main (int argc, char ** argv [])
{
printf ("%09d: CreateMutex () \n", GetTickCount ());
HANDLE mtx = CreateMutex (0, 0, "Test_mutex");
if (mtx! = NULL) {
printf ("%09d: WaitForSingleObject () \n", GetTickCount ());
WaitForSingleObject (mtx, INFINITE);
printf ("%09d: Lock\n", GetTickCount ());
system ("pause");
printf ("%09d: CloseHandle () \n", GetTickCount ());
if (! CloseHandle (mtx)) printf ("%09d: CloseHandle () error\n", GetTickCount ());
}
printf ("%09d: Sleep () \n", GetTickCount ());
Sleep (2000);
printf ("%09d: end\n", GetTickCount ());
return 0;
}

The first process:

 041522109: CreateMutex ()
041522109: WaitForSingleObject ()
041522109: Lock
For continuation push any key...
041539515: CloseHandle ()
041539515: Sleep ()
[color=red] 041541515 [/color]: end 

The second process:

 041534125: CreateMutex ()
041534125: WaitForSingleObject ()
[color=red] 041541515 [/color]: Lock 

2

Re: CloseHandle () does not remove lock named

Never with the such worked, decided to esteem to dock. In MSDN by English letters on the white it is written:
[quote =] Only one thread can own a mutex at any given time. The owning thread uses the ReleaseMutex function to release its ownership.