|
|
1.1 ! root 1: Sample: Using Named Mutexes Between Independent Processes ! 2: ! 3: Summary: ! 4: ! 5: MUTEX demonstrates using a named mutex between independent ! 6: processes. ! 7: ! 8: More Information: ! 9: ! 10: A mutex is often more appropriate to use between processes ! 11: than a semaphore. A potential drawback to the semaphore is ! 12: that any thread, even a thread not having control of the ! 13: semaphore, can call the ReleaseSemaphore function and change ! 14: it's use count. Another drawback is that if a thread gains ! 15: control of a semaphore, modifying the semaphore's use count ! 16: denies access to the semaphore by other threads or ! 17: processes; if that thread dies before calling ! 18: ReleaseSemaphore and changing the use count back, no other ! 19: thread or process will be able to gain access to the ! 20: semaphore. On the other hand, when a thread having control ! 21: of a mutex dies, the use count on the mutex is automatically ! 22: modified to allow other threads and processes access to it. ! 23: ! 24: To Use: ! 25: ! 26: Start any number of instances of this application. Each ! 27: instance will start a thread which will request access to ! 28: the mutex. when the thread has the mutex, it will print a ! 29: message in the application window "I HAVE CONTROL OF THE ! 30: MUTEX!", and then sleep for two seconds. It will then wake ! 31: up, erase the message, release the mutex; and then sleep for ! 32: another two seconds before asking for control again. By ! 33: starting several instances, you will see that each instance ! 34: will often have to wait longer than it's two seconds before ! 35: it gets control. ! 36: ! 37: ! 38:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.