I'm wondering if there's a package or model that will help me solve this scenario.
Let's say I have 3 threads and a bunch of objects A,B,C,D,E,F
- T1 needs locks A,B
- T2 needs locks B,C,D
- T3 needs locks E,F
In this scenario, it'd be ok if T1 & T3 ran simultaneously. Also, T2 & T3 can run simultaneously. But T1 & T2 should never run simultaneously.
Also, note that
- Threads can obtain an arbitrary number of locks, not just 2. (I saw an elegant solution to this problem with a fixed number of locks but not sure I can apply it here.)
- Obviously, I'd like each thread to acquire all the needed locks at the same time to prevent deadlock.
If someone can point me to a package that supports this use case, or some snippet of code that resolves this, please let me know.
Thanks so much.