I will call the next thread management code i make 'Loom'.
Threading or multicore programming is the fun activity of making a program run on more then one core. In 2005 the Free Lunch was Over and the focus shifted from increased clock speed to multiple cores among the chip designers. All the major target platforms are now multicore, that is they have more then one CPU's that (often) share instruction sets and memory.
Speed/Cores/Threads by platform
2000 PS2 0.299 GHz 1 1 mps
2001 XBox 0.733 GHz 1 1 x86
2006 Wii 0.729 GHz 1 1 PowerPC
Core: A core is another name for CPU so a dual-core processor contains two independent CPU's. The CPU is the part that read and execute program instructions. The cores share the same processor resource like cache and memory interface. The common setup is that all cores are of the same type but in the PS3 there where two different types of cores. Two to eight cores are common.
Threads: With two cores the processor can run one lines of execution, or a thread on each core at the same time. A program (process) that runs more then one thread is called multi-threaded. If it creates two threads each one can each be assigned to it's own core so they can both run at full speed. When the program is run on a single core processor the operating system need to switch between the threads in the application so each on gets to run a little at the time on the core. The two threads created by the program is called software threads and when they run they do it on the hardware thread on the core.
Software threads: A program such as a game can create multiple threads. All the threads share the same memory address space. The OS selects what hardware thread the thread will run on. The OS can switch a thread from a core to another.
Hardware thread: A core can also support more then one hardware thread. This is known as Simultaneous multi-threading (SMT) or as Intel call it Hyper-threading. The hardware threads share the cores resources such as l1 cache and execution unit. When one hardware thread is stalled due to things like a cache miss or a branch mispredict the other thread(s) can use the core resources to do some work. Most common is that there are support for two hardware threads per core.
The cores are often called physical cores and the hardware threads are listed as logical cores. A four core processor with SMT will be shown as an eight core logical processor in the OS.
With processor affinity one can select what cores a thread is allowed to run on. On fixed hardware such as a console platform it is possible to use hard affinitys and lock a thread to a specific core. On open platforms such as PC it needs to play along with the rest of the system.
Threadsafe - How to handle shared data.
Synchronization - How to keep every thread arriving at the castle at the same time.
Concurrent programming - Concurrent programming is how to program multi-threaded programs.
Thread API - Choose your poison.
multithreading and vfx - 2017
Simple Parallel Rendering - 2017
The Deadlock Empire - 2016
Multithreaded Gameplay - 2015
Going Parallel: Overture - 2015
Concurrent Servers - 2017