Your program will ensure mutual exclusion between different calls to add-user!
. But the semaphore doesn't protect against anything that isn't checking it, so calls like get-name
could run in between the two hash-set!
calls. So the answer to 1 is "yes, you need to worry about that".
If you only have this one data structure that you're protecting, then just using the same semaphore for everything should be fine. If you have a more complex situation than that, then I highly recommend using multiple threads and communicating via channels, rather than sharing mutable data between threads.