Understanding Threads and Locks Flashcards
Explore essential concepts of threads, locks, and concurrency with these engaging flashcards. (9 cards)
What is deadlock?
Deadlock is when two or more threads become blocked, because they are each waiting for something the other thread has. This reliance is a mutual dependancy between the two.
What is lock overhead?
Locking is storage expensive, as it is another variable that needs to be maintained. This required storage is called lock overhead.
How can you mitigate lock overhead?
If there’s a cost associated to a lock, reduce overhead by having fewer locks. You can decrease the number of locks by locking larger amounts of code
What is lock contention?
Lock contention is the time spent waiting for another thread to give up a lock, so work can be continued
How can you mitigate lock contention?
You can reduce lock contention by placing locks on smaller amounts of code. This means less code has to be completed before a lock is given up.
What is a thread pool?
You can create multiple threads to begin with, and assign them tasks, rather than creating threads as you go along
What is an advantage of thread pools?
There is no overhead for creating new threads, you just use ones from the pool
What are 2 disadvantages of thread pools?
1) Deadlock may happen if you run out of threads (a locked action will not unlock until right amount of threads available for task completion) 2) Thread leakage, if a thread has an exception not dealt with, the thread cannot be used
What is the difference between threads and co-routines?
1) Threading offers concurrency and parallelism. Coroutines offer concurrency but not necessarily parallelism. 2) Coroutines yield control at fixed points, Threading does not, leaves that to the processor.