File:  [WindowsNT SDKs] / q_a / samples / mutex / readme
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 18:29:19 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: ntsdk-jun-1992, HEAD
Microsoft Windows NT Build 297 06-28-1992

 Sample: Using Named Mutexes Between Independent Processes

Summary:

MUTEX demonstrates using a named mutex between independent
processes.

More Information:

A mutex is often more appropriate to use between processes
than a semaphore.  A potential drawback to the semaphore is
that any thread, even a thread not having control of the
semaphore, can call the ReleaseSemaphore function and change
it's use count.  Another drawback is that if a thread gains
control of a semaphore, modifying the semaphore's use count
denies access to the semaphore by other threads or
processes; if that thread dies before calling
ReleaseSemaphore and changing the use count back, no other
thread or process will be able to gain access to the
semaphore.  On the other hand, when a thread having control
of a mutex dies, the use count on the mutex is automatically
modified to allow other threads and processes access to it.

To Use:

Start any number of instances of this application.  Each
instance will start a thread which will request access to
the mutex. when the thread has the mutex, it will print a
message in the application window "I HAVE CONTROL OF THE
MUTEX!", and then sleep for two seconds.  It will then wake
up, erase the message, release the mutex; and then sleep for
another two seconds before asking for control again.  By
starting several instances, you will see that each instance
will often have to wait longer than it's two seconds before
it gets control.




unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.