Author Topic: Synchronization - Mutex - CMutex, CSingleLock, WaitForSingleObject  (Read 1432 times)


  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Multithreading are very interesting part of programming languages. Visual C++ offers many ways to support  multithreading. You can create thread easily using _beginthread function.

Mutex objects are used to synchronize between multiple processes rather than multithread. Named mutexes can be created and accessed between two applications (client/server or peer to peer).

In this example, I have written one application using mutex. It will check whether any other instances of the same application is running or not. If another instance is running, then it will display the message "another instance of the same application is running" and then it will exit.

Note that if you are using mutex between multiple threads and mutex object is defined globally, the thread which is locking should be responsible for unlocking the mutex object. If you try unlock the mutex object with another thread, it would fail with the GetLastError return code - 288 ERROR_NOT_OWNER - Attempt to release mutex not owned by caller.

For source code, visit at:


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1