Is there a platform independent way in C++11 (boost is available) to make sure that only one instance of an application is started at a time? (I'd prefer not to run with the "file and (f)lock" method as it requires platform specific code, but I will do so if there is no better way.)
There is no (simple) other way like an unavailable port that I can use as a criterion in my scenario neither. And yes, I am aware of DOS problems - so no need to point those out.
I found the following similar question suggesting a solution with boost. The solution has two problems though:
- Minor: It seems a call to
shared_memory_object::remove("shared_memory");
is missing (in the case "the race was won"). But I am not really familiar withboost::interprocess
, so maybe I am wrong?! - Major: If the program crashes the shared memory is still existing and thus the next instance of the program will fail to start.
I also found this question. No answer there that excites me. But it's a C++98 question so maybe with C++11 or boost there is a new/different way now?