Threading Issues
fork() and exec()
fork() - duplicates the calling thread or all the threads, Depending on the version of fork you are using
exec() - replaces all the processes and the threads
Signal Handling
Signals - used in UNIX systems to notify a process that a particular event has occurred.
A signal handler is used to process signals:
- Signal is generated by particular event
- Signal is delivered to a process
- Signal is handled by one of two signal handlers:
1. default
2. user-defined
default handler - a process that the kernel runs when handling a signal (signal handlers can override this)
where is the signal sent?
- sent to the thread its addressed to
- to all threads in the process
- to certain threads in the process
- one thread just gets all the signals
Thread Cancellation
Thread Cancellation - This is where you terminate a thread before it is finished
Target Thread - thread to be canceled
approaches:
- Asynchronous cancellation - terminates the target thread immediately
- Deferred cancellation - allows the target thread to periodically check if it should be cancelled
Invoking thread cancellation requests cancellation, but actual cancellation depends on thread state

If thread has cancellation disabled, cancellation remains pending until thread enables it, (or when it reaches its cancellation point)
Thread-Local Storage
Thread-local storage (TLS) - allows each thread to have its own copy of data
- Useful when you do not have control over the thread creation process (i.e., when using a thread pool)
- Different from local vars, since this is available across all functions in the thread, akin to
staticdata
Scheduler Activations
- Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application
- lightweight process (LWP) - an intermediate data structure between User and Kernel Threads
- Appears to be a virtual processor on which process can schedule user thread to run
- Each LWP attached to kernel thread

- Scheduler activations provide upcalls - a communication mechanism from the kernel to the upcall handler in the thread library
- This communication allows an application to maintain the correct number kernel threads

