Content deleted Content added
m Reverted edits by 96.39.43.166 (talk) (HG) (3.1.22) |
→Motivation: Replace "is undesirable" with "can be undesirable" since the former implies that it undesirable in all cases. |
||
Line 14:
The traditional approach to multi-threaded programming is to use [[Lock (computer science)|locks]] to synchronize access to shared [[resource (computer science)|resources]]. Synchronization primitives such as [[mutual exclusion|mutexes]], [[Semaphore (programming)|semaphores]], and [[critical section]]s are all mechanisms by which a programmer can ensure that certain sections of code do not execute concurrently, if doing so would corrupt shared memory structures. If one thread attempts to acquire a lock that is already held by another thread, the thread will block until the lock is free.
Blocking a thread
Other problems are less obvious. For example, certain interactions between locks can lead to error conditions such as [[deadlock]], [[livelock]], and [[priority inversion]]. Using locks also involves a trade-off between coarse-grained locking, which can significantly reduce opportunities for [[parallel computing|parallelism]], and fine-grained locking, which requires more careful design, increases locking overhead and is more prone to bugs.
|