Problem:
There may be times when you need to coordinate work between multiple instances of a process that are sharing a resource. One process will use the resource while another waits for access to that same resource. To do this, you can use the CreateMutex and WaitForSingleObject Win32 API functions.
Resolution:
We can use the CreateMutex Win32 API function to protect a shared resource from simultaneous access by multiple processes. Each process must wait for ownership of the mutex before it can execute the code that accesses the shared resource.
See the comments in the source files of the attached demo for details.
Additional details of these functions can be found at http://msdn.microsoft.com/library/