Multi-threading

A software thread is the “Smallest sequence of programmed instructions that can be managed independently by a scheduler” [Wikipedia]

A thread has its own:

  • Program counter
  • Registers
  • Stack
  • Thread-local memory (better to avoid in general)
  • Threads of a process share everything else, e.g. Program code, constants, Network connections

To make code thread-safe, it is important to know what objects are shared and know when they are shared. The difficulty depends on the context.

 

Guidelines for writing thread-safe modules (from this wiki page).

  1. Remove class data members that are intended to be valid for each event.
  2. If TFileService is used in event-level functions, then
    1. If using a shared module, serialize(...) must be called inside the constructor body, or
    2. Use a legacy module

For more information, please see: