← BYTES
Unix IPC·Starter·Ref: 15.1.76

What typically happens if a thread tries to lock an ordinary (non-recursive) mutex that it is already holding itself?

Have a question about this video? Mention reference 15.1.76 when you contact us.

a.The second lock attempt always succeeds instantly with no issue of any kind
b.The operating system automatically kills the other threads in the program to resolve the conflict
c.The mutex automatically converts itself into a recursive mutex
d.This is undefined behavior or a self-deadlock for a standard, non-recursive mutex -- the thread ends up waiting forever for itself to release a lock it's still holding
A plain, non-recursive mutex doesn't know or care that the second lock attempt came from the SAME thread that already owns it -- it just sees 'this mutex is currently held,' and the thread ends up waiting for itself to release something it's still holding, which never happens: a classic, easy-to-cause self-deadlock bug.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES15176#UnixIPC