W9 - Intro to Threads Flashcards

(16 cards)

1
Q

Two parts of a traditional process with a single thread of execution

A

Sequential program execution stream
- this is the code executed as a sequence. includes state of CPU registers, stack, …

Protected resources
- main memory state, I/O state, …

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

Thread

A

A sequential execution stream within a process.

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

Is there protection between threads?

A

No. Threads share the process’s resources.

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

Multithreading

A

A single program made up of a number of different concurrent activites (threads of execution).

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

Creating process vs creating thread

A

New thread will use less memory, takes less time to create, and terminate faster.
Threads naturally share memory for communication, for processes the kernel needs to provide protection and mechanisms for communiation.

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

Benefits of multi threading

A
  • Exploit multiple cores
  • If one task blocks on I/O other tasks in the program should still be able to execute (increased responsiveness)
  • Some problems are best structured as communicating tasks (gui should be responsive)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What state is shared by all threads in process

A

Content of memory (global variables, heap)
I/O state (file descriptors, network connections)

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

How are threads useful in a web server as an example

A

Threads are created to process requests and issue responses. In the meanwhile the server continues to listen for other requests. Other threads to read data, access DB, etc, can also exist.

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

Why choose multi threading over multiple processes

A

Context switch expensive compared to thread switch.
Thread creation/termination is faster than process creation/termination.
Threads naturally share memory

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

What does our single threaded process model look like?

A

Process control block
User address space
User stack + kernel stack (just this one pair)

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

What does our multi threaded process model look like?

A

Process control block
User address space (shared between all threads)
Multiple threads, each made up of:
- Thread control block
- User stack + Kernel stack

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

What state remains private to each thread (typically kept in kernel memory)

A

TCB (Thread control block)
Thread ID
CPU registers (including PC)
Execution stack pointer
Scheduling info (e.g. priority)
Pointer to the PCB

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

Reminder: What’s a PCB

A

Process Control Block is a data structure used by the OS to keep track of processes

It has:
- PID
- Process State
- PC
- CPU Registers
- Mem management info
- Scheduling info
- I/O Status
- If multithreaded, thread list or TCBs.

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

Benefits of using processes over threads

A

Much simpler, since theres no uncontrolled access to shared variables and you can avoid all sorts of errors.

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

Thread Control Block

A

Private info individual to the thread stored here.
- TID
- CPU registers (including PC)
- Execution stack ptr
- Scheduling info
- Pointer to PCB

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