The Thread Analyzer can detect potential deadlocksĪs well as actual deadlocks. The Oracle Solaris Studio Thread Analyzer is a tool that you can use When using multiple locks, avoid deadlocks by making sure that all threads acquire the locks in the same order. So, fix only those locks that have measured contention. Most locks are held for short amounts of time and contention is rare. In general, start with a coarse-grained approach, identify bottlenecks, and add finer-grained locking where necessary to alleviate the bottlenecks. Try not to hold locks across long operations like I/O where performance can be adversely affected.ĭo not hold locks when calling a function that is outside the module and might reenter the module. Use calls to sched_yield() to make threads share time asįollow these simple guidelines for locking. The sched_yield() functionĪllows other threads to run and to acquire the lock.īecause the time-slice requirements of applications are so variable, the system does not Just before the call to reacquire the lock. You can usually solve this type of problem by calling sched_yield()(3C) Consequently, that threadĬontinues to run from the time the thread releases the lock until the But, nothing blocks the thread holding the lock. The lock was released, the appearance is that the other thread should acquire Lets a small amount of time pass, and then reacquires the lock. This problem usually happens when the thread holding the lock releases the lock, Problem can occur where a particular thread never acquires a lock. Deadlocks Related to Schedulingīecause the order in which locks are acquired is not guaranteed, a When contention occurs, the held locks must usually beĭiscarded and the locks reacquired in order. This behavior of primitive variants allows threads to violate the lock hierarchy The blocking synchronization primitives usually have variants that attempt to get a lockĪnd fail if the variants cannot get the lock. The state of the module must be reevaluated. Lock A and then reacquiring mutex lock B in that order causes the Instance, thread 2 has many assumptions about the state of the module while When all threads always acquire locks in the specified order,Īdherence to a strict order of lock acquisition is not always optimal. This kind of deadlock is avoided by establishing an order in which locksĪre acquired, a lock hierarchy. So, this condition is a permanent blocking of the Thread 2 cannot proceed while blocked waiting for mutex lockĪ. Thread 1 cannot proceed while blocked waiting for That thread 1 tries to acquire mutex lock B and thread 2 tries To be sure the intended operation is still valid.Īn example of another kind of deadlock is when two threads, threadġ and thread 2, acquire a mutex lock, A and B, respectively. The call completes and the locks are reacquired, the state must be verified In particular,Īvoid calling functions that call back into the module without reestablishing invariants andĭo not drop all module locks before making the call. The module that might depend on this module through some path. The solution for this kind of deadlock is to avoid calling functions outside Protected by the same mutex lock, the function deadlocks too. If aįunction calls code outside the module that circuitously calls back into any method Then, any call between theįunctions within the module protected by the mutex lock immediately deadlocks. Recursive deadlock is very easy to programįor example, assume that a code monitor has every module function grab the In a self deadlock or recursive deadlock, a thread tries to acquire a The most common error that causes deadlock is self deadlock or recursive deadlock. Not mean that a deadlock has not occurred somewhere else. Just because some thread can make progress does Deadlock is a permanent blocking of a set of threads that are competingįor a set of resources.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |