I'm trying to develop an application that consists of a pool of threads, using a work-stealing algorithm to concurrently execute tasks.
These tasks
- access a predefined set of objects;
- must "atomicly" acquire read/write permissions on all objects it accesses before actually running;
- upon finishing (and are guaranteed to eventually finish) release the objects they acquire.
One possible way to to solve this problem is to have each thread pick up a task at a time, then try to lock each of the objects using a predefined order. If at least one fails release all the locks, and proceed with another task.
This method however increases the probability of starvation of tasks with big object dependencies, and may even incur in live locks.
Is there another method to acquire a set of locks while maximizing concurrency? (without a global lock) Or perhaps change the system in a way that it is no longer required? If so, any good papers about it?
ps: As thiton answered, this is a generalized version of the "dining philosophers" problem. I am looking for non-centralized solutions, in particular algorithms that fare well in high load (addition and deletion of tasks).