I'm using a named mutex to detect other instances of my application and exit accordingly, and found that there are two ways of doing this:
- Create the mutex; ignore the indication whether it already existed; try to acquire it; use the fact that acquire succeeded/failed.
- Create the mutex; use the indication whether it already existed.
I can't decide whether to acquire the mutex (and release on exit). On the one hand, acquiring+releasing even though it makes no known difference looks like cargo culting, but on the other hand the existence of a mutex object sounds like a side-effect of its actual intended functionality.
So, should I do #1 or #2 to detect if the app is already running?