Search code examples
systemmutexdeadlock

Operating Systems: deadlock possible if a process can only lock one mutex at a time?


Is a deadlock possible in an operating system which disallows nested locking, so that a process can only lock one mutex at a time?

I think it wouldn't be possible, since for a process to acquire another lock it would need to release any lock it's holding. but I am not that familiar with deadlock situations. Is my logic correct?

Thanks.


Solution

  • This depends how you define lock, if you mean any activity with the potential to block then yes, it would be correct that the if a deadlock is not possible if only one lock can be taken at once. If you only mean explicitly created mutexes and semaphores deadlock is still possible as there are things other than taking a lock which can cause blocking.

    However the only implementations I know of which did something like this were old operating systems which had only a single lock for all shared resources and effectively only allowed a single thread to be in kernel space at once. This causes exceedingly poor performance in multi core systems, it is better to use other techniques such as ordered lock acquisition and time-outs in a modern multi-core or multi-cpu system rather than revert to this technique.