A distributed semaphore

distributed-semaphore

distributed-semaphore has been developed to synchronize some programs running on different machines. It was necessary to access some files via NFS from different machines, but those files could not be accessed by a reader process and a writer on at the same time. Since the processes could be run on different machines a daemon has been developed to synchronize them.

Most of the work was done by Emanuele Di Giacomo. Thanks Emanuele for doing this exceptional work!

Consumers and producers

The processes which have to access the shared resources exclusively are called producers. There can be only one producer at one time. The processes which can access the shared resources concurrently are called consumers. There can be many consumers at one time.

If a producer contacts the daemon and enter its protected section every other client (both other producers or other consumers) waits until the producer ends. If a consumer contacts the daemon an enter its protected section every other producer waits until the consumer ends but the other consumers can access the resource.

Dead lock condition

Since there is no smart way to detect process aliveness through network, so there is not a smart way to avoid dead lock conditions. This happens when a client contact the daemon and receives the permission to use the resources but then it dies before contacting the daemon back telling that it has done. The daemon uses an id provided by the client to keep track of the requests so that id can be used to remove the request by hand.