Lecture 6: Threads Flashcards

1
Q

Thread

A

“Lightweight Process”
Abstraction only of CPU (not memory) : basic unit of CPU utilization
Includes: thread ID, PC, registers, stack
shares with other threads of same process: code, data, files

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

Steps for Creating new processes:

A
  1. Allocate Memory
  2. Copy Text code
  3. Copy Data
  4. Copy Stack
  5. Copy File Descriptors
  6. Copy Registers
  7. Copy PC
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Responsiveness:

A

interactive program (e.g., multithreaded web browser) can keep running even if one thread (e.g., loading images) blocks

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

Resource Sharing

A

Code, address space sharing comes for free with threads. For processes, code copying required for former, IPC for latter

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

Economy

A

Slightly cheaper to context switch

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

Utilization of Multiprocessors->Scalability

A

Better parallelism: threads of same process can run spread across multiple cores at the same time.

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

Kernel Thread

A

Managed by OS with multi threaded architecture (Win 7, OS X, Linux, …) similar to a process in the single-threaded system.
- the kernel thread is the unit of execution that is scheduled by the kernel on the CPU

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

User Thread

A
Implemented with threads library (e.g., Java threads)
relationship to kernel threads:
1. Many-to-one
2. One-to-one
3. Many-to-many
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Many-to-One

A

Many user-level threads mapped to single kernel thread

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

Many-to-one Pros and Cons

A

+ managed by the thread library -> efficient
- one thread blocking causes all to block
(process blocks)
- multiple threads may not run in parallel on
multicore systems -> only one may be in
kernel at a time
- few systems currently use this model

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

One-to-One

A

Each user-level thread mapped to a kernel thread

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

One-to-One Pros and Cons

A

+ runs on multi processors
+ more concurrency than many-to-one (no blocking of threads in the same
process)
-number of threads per process sometimes restricted due to overhead of
creating a kernel thread for each user thread

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

Many-to-Many

A

Allows Many User Level Threads To Be Mapped To Many Kernel Threads

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

Many-to-Many Pros and Cons

A

+allows the operating system to create a
sufficient number of kernel threads
+can run in a multiprocessor
+ no process blocking

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

Joining Threads

A

Parent calls child.join()
• Causes parent to wait until child.run() completes
• If child is interrupted (run() doesn’t complete), will throw
exception that parent should catch

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

Cancelling Threads

A

• Any thread can cancel any other thread it knows about
- how?: invokes interrupt() on thread
• Interrupted thread must be implemented to periodically check its interrupt flag
• - is interrupted ():Returns true or false
• - interrupted ():Returns true or false & clears
interrupt flag
• Thread code specifies what to do upon detecting interrupt flag

17
Q

Multithreading vs. Multiprocessing

A
  • Cheaper context switch

* Much cheaper to fork new threads than to fork new processes

18
Q

User-Level vs. Kernel-Level

A
  • Management of user-level threads via user-level libraries

* Management of kernel-level threads via kernel + interrupts