+ Reply to Thread
Results 1 to 2 of 2

Thread: What is Mutex?

  1. #1

    What is Mutex?


    What is Mutex? How it is different than critical section?


  2. #2

    Mutex is synchronization object. You can use it to synchronize access to shared variable.

    Critical section is also a synchronization object and can be useful to synchronize access to shared variable.

    Following is difference:

    a. Mutex is a kernel object, it is slow than critical section.
    b. Can use WaitFor* APIs.
    c. Name mutex can work within the process boundaries.
    d. Mutex is in WAIT_ABANDONED state when owner of the thread terminates without releasing it.

    Critical Section:
    a. Critical section is user mode object, hence it is fast then Mutex.
    b. In Windows, one thread is allowed to lock critical section more than once.
    c. Critical section cannot use WaitFor* APIs.
    d. Critical section works only within the single application.

    void UsingMutex()
    	HANDLE hMutex = CreateMutex(NULL, TRUE, pszApplicationName) ;
    	if (NULL != hMutex)
                    ReleaseMutex(hMutex) ;
    		CloseHandle(hMutex) ;

+ Reply to Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts