Lecture 5 - Threads Flashcards

1
Q

What is a thread?

A

A small unit of execution within a process

Multiple threads can execute concurrently (using timeslicing like multiprogramming) doing different jobs within the process

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

How are threads created?

A

CreateThread(fn, arg0, arg1, …);

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

What two concepts does process abstraction combine?

A

Concurrency - each process sequential execution of stream of instructions

Protection - each process has its own address space

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

What do threads do, compared to processes?

A

Separate the concepts of concurrency from protection:

Sequential stream of instructions, like a process

SAME address space within process

Can communicate by updating memory - don’t need to send messages

Can execute on different cores - true parallelism

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

What is the difference between a single threaded and multithreaded process?

A

Single threaded - one thread - one set of registers, one stack

Multithreaded - multiple threads - a set of registers and stack each

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

What do threads offer that processes dont?

A

More efficient - less overhead to create

Sharing memory is easy/automatic

Can take advantage of multiple CPUs within the one process

Cheap context switching

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

What does the thread control block contain?

A

thread specific info: stack pointer, program counter, state, register values, pointer to pcb etc.

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

What library is used in C to get at threads?

A

pthreads

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

What function from pthreads can be used to create a thread?

A

pthread_create

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

What is the difference between a kernel thread and user-level thread?

A

Kernel thread - supported by OS, scheduling and synchronisation controlled by OS

User-level - supported by user level code, e.g. thread library - handles scheduling, creation, etc. kernel just sees the one process

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

What is the downside of kernel threads?

A

a bit expensive - each thread operation is a syscall

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

What is the downside of user threads/

A

If any thread in a process has to wait for the kernel, every other thread does too

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