enter() seems to always return true for me regardless of how many instances have supposedly locked it. Can anyone confirm that
InterprocessLock is working on macOS 10.12?
Testing this more, it works correctly on Windows, but the same code on Mac acquires the lock every time.
seems to always return true for me regardless of how many instances have supposedly locked it
but the same code on Mac acquires the lock every time
I could be wrong but this makes sense to me as an IP lock is ref-counted…
Both the Mac and Windows versions are ref-counted, though, so I’m not sure how that would account for the discrepancy we’re seeing.
InterprocessLock should be used to synchronise between different processes and not instances. If you want to synchronise between instances then you should be using a normal
CriticalSection - maybe wrapped in a singleton.
Thanks Fabian. We do need the lock across processes. Would the recommendation be to use a critical section AND an interprocess lock if we don’t know if we’re being placed in the same process or not?
Any reason this is different on Windows?
Yes, I would think that this is the best approach.
I guess that the underlying native API has different behaviour when two InterProcessLocks are held by the same process. Obviously, we should abstract this difference in behaviour away. I’ve added this to our backlog.
Thanks for the info!
Do you know if the current OS X implementation will gracefully deal with an abandoned lock? I know the Windows version has
WAIT_ABANDONED for this situation. Either way, it might be worth mentioning in the docs since the abandoned situation can be important for interprocess use.