Description
The current API for task blocking is prone to timing bugs, leading to deadlocking. Consider the current RecMutex
implementation:
https://github.com/hermitcore/libhermit-rs/blob/7c9327ef352d26ac0ba69c952530e9801b454cbd/src/synch/recmutex.rs#L26-L61
If a timer interrupt triggers a reschedule directly after calling block_current_task
, the state spinlock will not be unlocked, therefore any task trying to wake the current one will deadlock, too. In general, almost all uses of block_current_task
will need to do some operation after marking themselves as blocked, and are thus suffering from the same timing problem. Note however, that the current semaphore implementation prevents interrupts during its critical section, avoiding this problem. This is however not possible for user programs, such as the Parker
in std
.