Multi-threading conceps Flashcards
What is Concurrency?
Concurrency refers to the ability of a program to execute multiple tasks simultaneously.
What is a thread
A thread is the smallest unit of execution within a process.
Why do we need synchronization?
Synchronization is crucial when multiple threads access shared resources to avoid data corruption and ensure data consistency.
Explain what a Mutexe does
Mutexes provide a mechanism for mutual exclusion, allowing only one thread to access a shared resource at a time.
what is a deadlock?
Deadlocks occur when threads wait indefinitely for each other to release resources. Strategies like resource ordering and timeouts are used to avoid deadlocks.
What are condition variable?
Condition variables are synchronization primitives that allow threads to wait for a specific condition to be met before proceeding.
Disadvantage of thread scheduling
Context switching
Explain context switching
The process of loading/saving the current state of the thread. During this time the processor can not execute instructions.
What is Data Race
Occurs when 2 or more threads access the same memory location and at least one of the threads modify this memory location. Threads are not synchronized when they access this memory location.
What is critical section
Region of code that is executed by one or more threads.
What does join() do?
ensure that a thread has completed its execution before the program exits
Unique_locking()
Unique lock is similar to lock_guard(). However, it allows to call unlock()
Lost wakeup
When using condition variable. This condition occurs if the notify() is called before the wait()
How do we solve a lost wakeup?
Use wait() with a second argument, usually a bool
future and promise
Classes for transferring data between threads. These set up a shared state between threads
Share state
state where threads can transfer data. No beed for shared data variables and no explicit locking.
Producer in data transfer
Associated with promise
Consumer in data transfer
Associated with promise