Threading
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
----Year----Platform----Speed------Cores----HW Threads---Architecture
2000 PS2 0.299 GHz 1 1 mps
2001 XBox 0.733 GHz 1 1 x86
2006 Wii 0.729 GHz 1 1 PowerPC
2012 WiiU 1.24 GHz 3 3 PowerPC
Hardware
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.
Affinity
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.
Links
multithreading and vfx - 2017
Simple Parallel Rendering - 2017
C++11 Multithreading Tutorial via Q&A – Thread Management Basics - 2017
Top 20 C++ multithreading mistakes and how to avoid them - 2017
CPU core count detection on Windows - 2017
Parallel Computer Architecture and Programming - 2017
GCAP 2016: Parallel Game Engine Design - Brooke Hodgman - 2016
Multithreaded OpenGL Job-Based Render system test - 2016
The Deadlock Empire - 2016
Is Parallel Programming Hard, And, If So, What Can You Do About It? - 2016
Event based synchronization of threads with main game loop - 2016
Parallel Computer Architecture and Programming - 2015
Multithreaded Gameplay - 2015
Multithreading for Gamedev Students - 2015
Multi-Threading Best Practices for Gamedev - 2014
A Look Back at Single-Threaded CPU Performance - 2012
Squeeze the Juice Out of the CPUs: Post Mortem of a Data-Driven Scheduler - 2010
Parallel Graphics in Frostbite – Current Future - 2009
Sponsored Feature: Two Brains Are Better Than One -- How to Thread Game AI - 2009
Sponsored Feature: Designing the Framework of a Parallel Game Engine - 2009
Sponsored Feature: Multi-Threaded Fluid Simulation for Games - 2009
Sponsored Feature: OMG, Multi-Threading is Easier Than Networking - 2009
Sponsored Feature: Microsoft Flight Simulator X SOARS to New Heights with Multi-Threading - 2008
The Intersection of Game Engines and GPUs – Current & Future - 2008
Multithreading Optimization Basics - 2007
http://concurrencyfreaks.blogspot.se
Multi-Platform Multi-Core Architecture Comparison - 2008
Instruction Scheduling: Dual-Issue vs. Co-Issue
C++ atomics, from basic to advanced. What do they really do?
D3D12 Multi-Adapter Survey & Thoughts - 2017
Part 2 – Multi-threaded command recording and submission
Killzone Shadow Fall: Threading the EntityUpdate on PS4 - 2017
Simple job system using standard C++ - 2018
Video: Multi-Threading Best Practices for Gamedev - 2014
Going Parallel: Overture - 2015
https://crimild.wordpress.com/2015/06/27/going-parallel-an-overview/
Work-Efficiency vs. Step-Efficiency
Concurrent Servers - 2017
https://eli.thegreenplace.net/2017/concurrent-servers-part-1-introduction/
A Close Look at a Spinlock
https://blog.regehr.org/archives/2173