is it possible to generate a deadlock with single lock

deadlock, multithreading, mutex

Solution

It depends on how you define "deadlock" I guess, but I could see one possibility:

- Thread A grabs the mutex

- Thread B waits for mutex

- Thread A dies without releasing mutex

Thread B never runs.

Problem

This is an interview question . In general the deadlock between 2 threads is generated when thread1 locks mutex1,and a moment before it tries to lock mutex2 ,thread 2 locks mutex2.After that tread 2 wants to lock mutex1.So they wait for each other forever. The question was "Can you gave a scenario of deadlock with one mutex and any number of threads?"

Original source