gparmer/Composite — Issue #6: Possible deadlock between cbufs and component locking
Author: gparmer
Created: 2012-02-24 17:47:07+00:00
State: open

The following situation can occur with two threads that may lead to deadlock:

1. thread 0 allocates a cbuf, and is preempted by thread 1.
2. thread 1 allocates a cbuf (there are only 2 in the component), and then takes a component-wide lock (this problem persists regardless of lock granularity so long as t 0 and t 1 take the same lock).
3. thread 1 allocates a cbuf which causes it to call the cbuf_mgr and block with a dependency on t 0.
4. t 0 runs and tries to take the same lock, causing a dependency to t 1.

--> **Deadlock**.

Possible solutions:

- impose a lock hierarchy including the one used in cbuf_alloc
- enforce that we allocate all cbufs we may need at the start, or none at all (would require dynamic checking to see if the programmer does not follow this convention)