tags:

views:

625

answers:

3

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.

EDIT: I am motivated by curiousity, because in Rob Kennedy's comment under his (excellent) Answer to the above-linked Question, he implied that the choice of mutex name is non-trivial and should be the subject of a separate question.

EDIT2: The referenced question's goal was to ensure only a single instance of an app is running.

A: 

You could combine a description of what you're protecting against with the word "Guard"

Stephen Denne
+2  A: 

A really safe name for a global mutex is a description + a guid

For example:

"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.

EDIT

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.

Sam Saffron
...unless they copy your mutex's name intentionally... ;-)
Shog9
I'd say using GUID in names is going overboard with uniqueness paranoia.
Mohit Nanda
A: 

I haven't used GUID's in the past, but I'm starting to think its a good idea - if you think about all the developers in the world working of different software.

Unless you are thinking up quite obscure names that you can be assured are unique, you should think about GUID's.

Span