I only checked the Windows code.
If two processes start at about the same time, process A that doesn't receive ERROR_ALREADY_EXISTS may not yet have written into the mapping, while process B that received ERROR_ALREADY_EXISTS tries to read the mapping, which contains 0 at that point.
It looks like there's no way around using CreateMutexW() (and ReleaseMutex()) as well to synchronize the two processes. You could use the caller-provided name also for CreateMutexW() (but with an at least single-character prefix/suffix to avoid a conflict), which would limit that name to MAX_PATH, minus the length of a possible Local\(/Global\) prefix, minus the length of the mutex differentiation prefix/suffix. Or you could simply use the same fixed version-4 UUID (maybe with crate name prefix/suffix) for all apps and app instances, because process starts are relatively slow anyways and the blocking duration, if happening at all, would be very short.
I only checked the Windows code.
If two processes start at about the same time, process A that doesn't receive
ERROR_ALREADY_EXISTSmay not yet have written into the mapping, while process B that receivedERROR_ALREADY_EXISTStries to read the mapping, which contains 0 at that point.It looks like there's no way around using
CreateMutexW()(andReleaseMutex()) as well to synchronize the two processes. You could use the caller-provided name also forCreateMutexW()(but with an at least single-character prefix/suffix to avoid a conflict), which would limit that name toMAX_PATH, minus the length of a possibleLocal\(/Global\) prefix, minus the length of the mutex differentiation prefix/suffix. Or you could simply use the same fixed version-4 UUID (maybe with crate name prefix/suffix) for all apps and app instances, because process starts are relatively slow anyways and the blocking duration, if happening at all, would be very short.