one Rust program keeps some socket open. Another program sends a lock request, and if no lock obtained yet, gets the lock. All other Rust programs need to wait until the lock released.
Same approach, but with a file keeping a lock.
How it's related to Rust? I can see only polling approach which is a waste of resources, and also has a risk that some requester doesn't get the lock ever, or another risk of a deadlock, when the lock never gets released. Is there an embedded mechanism in Rust to solve the problem, or there is nothing to do with Rust?
The socket approach requires a reliable, distributed locking protocol, which is quite difficult to design since you have to assume any process could abort abnormally. But this approach is only needed when the processes are not all running on the same machine.
File locking is much simpler when all processes have access to a local file system, and it is known to work well. However, Rust file locking APIs are unstable/nightly. So you'd either have to use these unstable APIs, or use platform specific APIs.
Thank you for the input. Yes, all processes are local in my case, and a file based approach looks simpler. I am fine with night builds, since the project is POC level anyway. I will take a look for the Rust API.