Lecture 5 Flashcards

1
Q

Many-to-many

A
  • Mapping is not fixed, need a thread scheduler
  • When a user thread blocks, kernel notifies thread scheduler (upcall) to select another thread to use a free kernel thread
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Pros and cons of many-to-many

A
  • Pro: Increased concurrency; flexible (users may create as many user threads as they want)
  • Con: Very complex to implement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

POSIX Pthreads

A
  • API specification, implementation is up to OS

- Common in UNIX systems

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

Windows Threads

A
  • Implementation of the one-to-one model in kernel
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Java Threads

A
  • Java threads are managed by JVM, which is run on top of OS
  • JVM specifies the interface, not the implementation
  • JVM uses thread services provided by the host OS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Threading Issues:

A
  • Semantics of fork() and exec() system calls
  • Signal handling
  • Thread pools
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If a process has multiple threads and one of them calls fork(), should the entire process be duplicated or just the calling thread?

A

It depends. If exec() is called immediately after fork(), there’s no need to duplicate all threads as they will be overwritten anyway. Otherwise, all threads should be duplicated.

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

Signals are used in UNIX to…

A

…notify a process that an event has occured

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

Two types of signal:

A
  • Synchronous (delivered to the same process that performed the operation that caused the signal)
  • Asynchronous (Signal generated by an external event, usually delivered to a different process)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Signal Sequence

A
  • Signal is generated by an event (eg. Ctrl-C pressed or packet arrived)
  • Signal is delivered to a process
  • Signal handler processes the signal (default by OS, can be user-defined)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Should OS deliver a signal to: all threads, one thread, or specific thread of a process?

A
  • Synchronous: deliver signal to thread

- Asynchronous: deliver signal to all threads belonging to the process

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

True or false: Threads cannot block signals

A

False

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

Interrupts vs Signals

A
  • Interrupts started by CPU, I/O, or software; signal started by kernel or process
  • Interrupts handled by ISR in kernel, signals handled by default signal handler in kernel, or by process that overrides it
  • ISR must be simple, signal handler can be complex and call other functions in the kernel
  • Kernel may map specific interrupts to signals and deliver them to processes for specific handling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Thread Pools

A

Create a set of threads that wait for work

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

Advantages of Thread Pools

A
  • Faster to service a request with existing thread than to create a new one
  • Limit number of threads in an application to pool size (further requests are queued until a thread is free)
  • Easy to manage resources
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Linux refers to threads and processes as…

A

…as tasks

17
Q

Thread creation is done through…

A

…clone system call

18
Q

Clone can be parameterized to allow different resource sharing responsibilities:

A
  • No sharing of resources between parent and child, the entire process is duplicated (same as fork)
  • OR, sharing of all resources between parent and child
19
Q

For resource sharing, only ____ are created for child

A

Pointers to shared resources

20
Q

Pros and Cons of Linux not differentiating between processes and threads

A
  • Good: Simplify scheduling

- Bad: Complex to correlate threads with their processes