Bloomberg LP Interview Question
Financial Software DevelopersCountry: United States
Interview Type: Phone Interview
Disadvantages of Locks:
1) adds overhead for each access, even when the chances for collision are very rare.
2) deadlock, where two threads each hold a lock on resources that the other needs before releasing its lock.
3) if one thread holding a lock dies before unlocking the resources, all other threads that are waiting on it will be blocked forever
4) high priority threads cannot proceed if a low priority thread is holding the common lock
etc....
Disadvantages of locks:
Only one thread can enter the critical section, if there are multiple readers and they can read at the same time, it is suboptimal in this case.
Deadlock:
It occurs when a thread or set of threads are waiting for each other to finish and thus nobody ever does.
"A deadlock cannot occur unless all of the following conditions are met:
Protected access to shared resources, which implies waiting.
No resource preemption, meaning that the system cannot forcibly take a resource from a thread holding it.
Multiple independent requests, meaning a thread can hold some resources while requesting others.
Circular dependency graph, meaning that Thread A is waiting for Thread B which is waiting for Thread C which is waiting for Thread D which is waiting for Thread A."
Starvation:
"Starvation is an equally-problematic condition in which one or more threads do not make progress."
disadvantages:
They cause blocking, which means some threads/processes have to wait until a lock (or a whole set of locks) is released. If one of the threads holding a lock dies, stalls/blocks or goes into any sort of infinite loop, other threads waiting for the lock may wait forever.
Lock handling adds overhead for each access to a resource, even when the chances for collision are very rare. (However, any chance for such collisions is a race condition.)
Locks can be vulnerable to failures and faults that are often very subtle and may be difficult to reproduce reliably. One example is the deadlock, where (at least) two threads each hold a lock that the other thread holds and will not give up until it has acquired the other lock.
Lock contention limits scalability and adds complexity.
Balances between lock overhead and contention can be unique to given problem domains (applications) as well as sensitive to design, implementation, and even low-level system architectural changes. These balances may change over the life cycle of any given application/implementation and may entail tremendous changes to update (re-balance).
Locks are only composable (e.g., managing multiple concurrent locks in order to atomically delete Item X from Table A and insert X into Table B) with relatively elaborate (overhead) software support and perfect adherence by applications programming to rigorous conventions.
Priority inversion. A low-priority thread/process holding a common lock can prevent high-priority threads/processes from proceeding. Priority ceiling protocol can be used to prevent priority inversion. Priority inheritance can be used to minimize priority-inversion duration.
Convoying. All other threads have to wait, if a thread holding a lock is descheduled due to a time-slice interrupt or page fault (See lock convoy)
Hard to debug: Bugs associated with locks are time dependent. They are extremely hard to replicate.
taken from wikki....
Disadvantage:
- T February 09, 2013Sometimes when using locks (for eg in case of a thread and interrupt handler), interrupts and/or pre-emption is disabled. As a consequence interrupts are ignored/queued and delayed or process can't swap and the higher priority process has to wait. Affects the normal OS operation.
Starvation:
The indefinite waiting by a thread because other threads keeping coming in.
Deadlock:
Number of threads waiting for resources held by other threads.