Quiz 5 Flashcards

(24 cards)

1
Q

What is a thread?

A

A new abstraction for a single running process

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

What characterizes a multi-threaded program?

A

It has more than one point of execution

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

What do multiple threads share in a multi-threaded program?

A

The same address space

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

What is needed to store the state of each thread?

A

One or more thread control blocks (TCBs)

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

What happens during a context switch between threads?

A

The register state of the running thread is saved and the register state of the new thread is restored

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

What does the code segment contain?

A

Instructions for the program

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

What does the heap segment contain?

A

Dynamic data structures and malloc’d data

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

What does the stack segment contain?

A

Local variables, arguments to routines, return values, etc.

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

Why use threads in programming?

A

To achieve parallelism and improve program speed on modern hardware

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

What does parallelization refer to?

A

Transforming a single-threaded program into a multi-threaded program that can run on multiple CPUs

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

What is a critical section?

A

A piece of code that accesses a shared variable and must not be concurrently executed by more than one thread

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

What is a race condition?

A

A situation where the results depend on the timing of execution of the code

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

What is the ideal approach for ensuring atomicity in critical sections?

A

Make the increment operation a single assembly instruction

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

What is the purpose of locks in multi-threading?

A

To provide mutual exclusion to a critical section

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

What function is used to create a thread in C?

A

pthread_create()

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

What parameters does pthread_create() take?

A

thread, attr, start_routine, arg

17
Q

What is pthread_join() used for?

A

To wait for a thread to complete

18
Q

What should you not do when returning a pointer from a thread?

A

Do not return a pointer to a local variable from a thread that is being terminated

19
Q

What must be done before using locks?

A

All locks must be properly initialized

20
Q

How can locks be initialized dynamically?

A

Using pthread_mutex_init()

21
Q

What flag must be added when compiling code that uses pthreads?

22
Q

What is the expected result of incrementing a shared counter in a race condition?

A

Indeterminate result

23
Q

Fill in the blank: A multi-threaded program has more than one point of _______.

24
Q

True or False: The stack of each thread is shared among all threads.