Skip to content

Trap deadlocks #11

@lucasart

Description

@lucasart

In mtx_lock(), I think you should trap the dead-lock with an assert:

if(res == EDEADLK) {
    assert(false);  // Dead-locks are undefined behaviour
    return thrd_busy;
}

According to the C11 standard, a dead-lock is undefined behaviour. However, with POSIX threads, the behaviour is well defined. What we want to avoid is client code silently discarding dead-locks, by calling mtx_lock(), without paying attention to the return value, which turns into a no-op. Instead code should crash, at least in debug compiles, so programmers can see that they are relying on a deadlock (which is undefined).

What do you think ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions