Slides 7 Flashcards

1
Q

How do threads compare to processes?

A

They are more efficient

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

What are some things threads share and don’t share?

A

share:
code
data
open files

don’t share:
registers
stack
Program Counters

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

What are some common thread scenarios?

A

pipeline
• a task is broken into a series of stages, where output of stage (i) is input
to stage (i+1)
• each stage handled by a different thread

manager/worker (aka master/slave)
• one manager thread assigns work to worker threads • manager thread handles all I/O
• worker threads can be static or dynamic

peer
• all threads work on the same or different tasks in parallel

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

What is a thread pool?

A

thread pool ― a so􏰁ware design pa􏰂ern
• program creates and maintains a pool of worker threads
• pool size can be tuned, eg. to the available computing resources
• when program needs a thread, it is takes one out of the pool
• when thread is done, program returns the thread back to the pool (thread recycling)

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

Do thread libraries make system calls?

A

Typically thread libraries contain higher level wrappers for system calls

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

How do you create a thread?

A

pthread_create(thread, attr, start_routine, arg)
thread = address of thread
attribute is idk
start_routine = function u want thread to execute
arg = address of argument for function you want thread to run on

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

What do the pthread exit and join functions do?

A

pthread_exit(status)
• terminates the current thread, similar to exit(), or you can return
from start_routine

pthread_join(thread, * status)
• blocks the calling thread until the specified thread terminates, similar to
wait()

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

How does signal handling work with threads?

A

some signals are thread specific:
• eg.SIGSEGV is delivered to the thread that caused the exception
• pthread_kill(thread_id, signal) is only delivered to the target thread
• most signals are delivered to the process
• only one thread will handle the signal (usually the main thread, but can be arbitrary)
•can change which thread handles which signal using pthread_sigmask()
• example: default behavior of → SIGINT, kills all threads

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

What are the properties of user level threads?

A

• threads are implemented entirely in user space
• requires no support from OS → can be used on OSes that don’t support threads
• each process has its own thread table and scheduler
threads usually switch only on I/O requests
• no need to trap into kernel when switching
threads, so they are very efficient
• allows custom management and scheduling
• requires OS to support non-blocking I/O
• each additional thread makes other threads run slower
• some issues with paging

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

What are the properties of kernel level threads?

A

one master thread table at the kernel level
• thread creation/deletion/scheduling done in the kernel space
works well when lot of blocking I/O ops needed
• processes with multiple threads run faster
• each thread can get same CPU time
• less efficient, since thread operations
need to trap into the kernel
• increased kernel complexity

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

What are the pros and cons of user level threads?

A
Pros:
no need for OS support
● fast context switch
● no traps are needed
● customized scheduling
Cons:
needs non-blocking system calls
● a thread may run forever
● page faults
● inefficient for threads with many
blocking procedure/system calls
● all threads get one time slice
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the pros and cons of kernel level threads?

A

Pros:
blocking calls are no problem
● OS aware of all threads → more efficient global scheduling

Cons:
some issues around fork()
● sending signals to threads

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

What are the 3 thread models?

A

N:1 (many-to-one) or user-level threads
• many user-level threads per single kernel thread
• thread management is done by the thread library in the user space • E.g., Solaris Green Threads, GNU Portable Threads
• 1:1 (one-to-one) or kernel-level threads
• maps each user thread to a kernel thread
• E.g., Windows NT/XP/2000, Linux, Solaris 9 and later
• M:N (many-to-many) or hybrid user/kernel level threads
• multiplexes many user-level threads to a smaller or equal number of
kernel threads
• eg. Marcel, a multithreading library for HPC

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