Skip to content

block_current_task is impossible to use correctly #442

Closed
@joboet

Description

@joboet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions