Which way to semaphore? File? Registry? CreateWindow? Something else?
Posted on 2004-04-06
I am writing a class which sometimes needs to pass semaphores (interprocess flags) to other instances of itself. (I don't want some functions run by more than one instance of the class on the same machine simultaneously.) I am hoping to distribute the class for use in a wide variety of environments and have been trying to figure out the best way to semaphore.
The component may be installed in an environment where it is not able to write to the disk, so I can't rely on temporary files.
I have considered using registry read/writes, but as it is possible to protect the registry, I am guessing that I can't really rely on any given key in the registry being writable either, plus I guess there's a bit of a performance overhead if I have to keep reading and writing to the registry all the time.
My current best guess is to use CreateWindow and FindWindow API calls, to create a window, and then check for it's existence. The only problem I can see with this method is that it assumes a single device context and so would probably not work in Terminal Server/Citrix environments.
Is there another method that I don't know about. How do you guys do it?