Re: multi-process locking



Ivan Novick wrote:

From people's experience, what do you think is the best technique for
locking a shared resource between multiple processes? I have seen
people use the file system and even some people use a oracle DB.

This is a tricky issue to handle really well.

fcntl() (aka record locks) are automatically freed if the holding process exits. This is both good and bad--it's good because someone else can take the lock, it's bad because the resource could be in a non-consistent state. If you use this type of lock, you should make sure that resource consistency is verified somehow--checksums on shared data, for instance.

Depending on your OS, you could also use process-shared pthread mutexes. These may be faster than the fcntl() locks, but will not be freed on process death, unless you also use the "robust" version.

In either case, if corruption in the shared resource is detected, you need to have some form of reinitialization strategy.

Chris
.



Relevant Pages