4 ms·
> There are so many more types of semaphores than most people realize This. For me, a semaphore is a general way handle states and dependancies with synchroni
by csdvrx 4y ago
> There are so many more types of semaphores than most people realize
This.
For me, a semaphore is a general way handle states and dependancies with synchronization.
Whether it's a file named ".lock" (like a simple traffic signal) or some fancy IPC (like a 4 way intersection between a segment with heavy traffic that gets the green light 99% of time, and one with low traffic, with cameras to detect cars on the small road for the 1% it will be useful, and pedestrian crossings with buttons to request a red ligh), it boils down to the same thing: enforcing states, with synchronization.
I'll make you laugh, but recently I used environment variables (!!) to do some basic semaphore without even a .lock file!
It may be ugly, but I needed something simple that would work on Windows and Linux. It did the job!
- askvictor 4y agoThere are plenty of types of locking mechanisms. A semaphore is a specific type of such. Sure, they might look different on different systems, or have different surfaces, but all should (or at least the ones I've seen) have an integer. Unless the term has been overloaded (sigh) and it's come to mean different things.
- csdvrx 4y ago> all should (or at least the ones I've seen) have an integer. To store integers like "5" with environment variables, I use export VARIABLE=5
- askvictor 4y agoThe point of a semaphore though is that it checks the value then modifies it in an atomic operation. If you can't guarantee the operation is atomic, you haven't solved the underlying problem.