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:

  1. Signal is generated by particular event
  1. Signal is delivered to a process
  1. 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?

  1. sent to the thread its addressed to
  1. to all threads in the process
  1. to certain threads in the process
  1. one thread just gets all the signals

Thread Cancellation

Pthread code
Java

Thread Cancellation - This is where you terminate a thread before it is finished

Target Thread - thread to be canceled

approaches:

  1. Asynchronous cancellation - terminates the target thread immediately
  1. 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

Scheduler Activations