Bloomberg LP Interview Question
Software Engineer / DevelopersCheck this out, its good:
cs.jhu.edu/~yairamir/cs418/os4/sld010.htm
Deadlock is a situation whereby two or more threads have locked resources needed by each other.
There are two schools of thoughts – Deadlock Prevention (a traffic light) and more promising, Deadlock Avoidance (a traffic police)
A deadlock occurs when a thread holds a resource and trying to acquire other resource already held by another thread,while that thread is also waiting for the first thread resource. Any number of threads can be involved in a deadlock if there is at least one resource per thread.Below are techniques to avoid deadlock:
1) Use sequence number with mutexes. Associate a sequence number with each mutex and acquire mutex in sequence. Never acquire a sequence number which is lower than sequence number already hold by thread.
2) Avoid locking more than one mutex at the same time.
in a multithreaded system, if the resource locked by one thread is needed by other and vice-versa, the system stops working. This is deadlock.
- morpheus February 12, 2009deadlock detection and avoidance is a problem in computer science, with many different approaches. these approaches would change with the system they are applied to.
a naive/beginner approach might be the logic that no thread/process should hold on to its resources if it can not find _all_ the resources it needs.