Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trap deadlocks #11

Open
lucasart opened this issue Apr 22, 2017 · 0 comments
Open

Trap deadlocks #11

lucasart opened this issue Apr 22, 2017 · 0 comments

Comments

@lucasart
Copy link

lucasart commented Apr 22, 2017

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant