Multi-threading conceps Flashcards

1
Q

What is Concurrency?

A

Concurrency refers to the ability of a program to execute multiple tasks simultaneously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a thread

A

A thread is the smallest unit of execution within a process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do we need synchronization?

A

Synchronization is crucial when multiple threads access shared resources to avoid data corruption and ensure data consistency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain what a Mutexe does

A

Mutexes provide a mechanism for mutual exclusion, allowing only one thread to access a shared resource at a time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a deadlock?

A

Deadlocks occur when threads wait indefinitely for each other to release resources. Strategies like resource ordering and timeouts are used to avoid deadlocks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are condition variable?

A

Condition variables are synchronization primitives that allow threads to wait for a specific condition to be met before proceeding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Disadvantage of thread scheduling

A

Context switching

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain context switching

A

The process of loading/saving the current state of the thread. During this time the processor can not execute instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Data Race

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is critical section

A

Region of code that is executed by one or more threads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does join() do?

A

ensure that a thread has completed its execution before the program exits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Unique_locking()

A

Unique lock is similar to lock_guard(). However, it allows to call unlock()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Lost wakeup

A

When using condition variable. This condition occurs if the notify() is called before the wait()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do we solve a lost wakeup?

A

Use wait() with a second argument, usually a bool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

future and promise

A

Classes for transferring data between threads. These set up a shared state between threads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Share state

A

state where threads can transfer data. No beed for shared data variables and no explicit locking.

17
Q

Producer in data transfer

A

Associated with promise

18
Q

Consumer in data transfer

A

Associated with promise