Search code examples
mutexnaming

Mutex names - best practice?


Related to this question, what is the best practice for naming a mutex? I realize this may vary with OS and even with version (esp for Windows), so please specify platform in answering. My interest is in Win XP and Vista.


Solution

  • A really safe name for a global mutex is <a description> + <a GUID>:

    MyApp Single Instance Mutex : {c96f7db4-d743-4718-bef0-8533a198bcca}
    

    By using a name like this there is absolutely no chance someone else will use the same mutex name as your mutex.

    Sniffing around with process explorer, you can see that GUIDs are used in a few places, though in general they are not used. A pattern that does emerge though is that the word "mutex" is used quite a lot and Microsoft seem to like using capitols.