chapter 26 - concurrency: an introduction Flashcards

(12 cards)

1
Q

What is a thread?

A

function of execution that shares memory with other threads in the same process

runs independently

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

Why is switching between threads cheaper than switching between processes?

A

No need to switch page tables

its in the same memory

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

What does each thread have that helps the OS manage it?

A

Its own Thread Control Block (TCB)

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

Two main benefits of using threads?

A

Parallelism (on multicore systems)

Overlapping I/O with computation (better resource usage)

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

Why not use processes instead of threads?

A

Threads are cheaper to create

Threads share memory easily; processes require IPC

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

What is the role of pthread_create() and pthread_join()?

A

pthread_create() starts a new thread

pthread_join() waits for a thread to finish

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

What problem arises when threads access shared variables without protection?

A

Race conditions → unpredictable and incorrect results

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

Why is incrementing a variable like counter++ not safe?

A

It’s made of multiple instructions, and threads can interleave during execution

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

What is a critical section?

A

A section of code that accesses shared data

must not be executed by more than one thread at a time

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

What is mutual exclusion?

A

A property that ensures only one thread can enter a critical section at a time

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

What is a race condition?

A

When two or more threads access shared data at the same time and the result depends on timing

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

How do we fix race conditions?

A

By enforcing atomicity in the critical section using synchronization primitives

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