|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Process-wide thread registry and lifecycle manager: the concurrency core of CMSDK. More...
#include "MemoryManager.h"Go to the source code of this file.
Classes | |
| struct | cmlabs::ThreadStats |
| Bookkeeping record for a single managed thread. More... | |
| struct | cmlabs::ThreadDataHeader |
| Header at the start of the ThreadManager's contiguous storage block. More... | |
| class | cmlabs::Runnable |
| Minimal cooperative-shutdown base class for objects that run a worker thread. More... | |
| class | cmlabs::ThreadManager |
| Singleton registry that creates, controls and profiles all CMSDK threads. More... | |
Namespaces | |
| namespace | cmlabs |
Macros | |
| #define | GETTHREADSTATS(data, id) |
| Compute the address of thread slot id inside storage block data. | |
Functions | |
| bool | cmlabs::TestThreadManager () |
| Legacy standalone smoke test for ThreadManager (predates the UnitTestRunner framework). | |
| static THREAD_RET THREAD_FUNCTION_CALL | cmlabs::ThreadMonitoring (void *arg) |
| Entry function of the monitoring thread; delegates to ThreadManager::threadMonitoring(). | |
Process-wide thread registry and lifecycle manager: the concurrency core of CMSDK.
ThreadManager is a singleton that owns the creation, monitoring and termination of every native thread the SDK spawns. All thread bookkeeping lives in one contiguous, relocatable memory block (header + occupancy bitfield + per-thread ThreadStats array), which makes it cheap to snapshot and to publish to diagnostic tools.
The Psyclone threading model in one paragraph. Higher layers map work onto threads in two ways: a continuous crank owns a dedicated thread for its whole lifetime (created here, terminated here), while a one-shot crank borrows a pool thread each time its trigger fires. Because each firing gets its own thread, the same crank function can be executing concurrently on several threads at once; any state it shares must therefore be independently synchronised. ThreadManager itself only provides the raw threads and their statistics; the pooling/queueing policy lives in the higher-level scheduling code.
Platform notes. The actual thread primitives are wrapped in utils:: (utils::CreateThread, utils::TerminateThread, ...): Windows uses CreateThread/SuspendThread/ResumeThread and CRITICAL_SECTION-backed mutexes, POSIX uses pthreads. On pthreads there is no portable way to read another thread's CPU usage, so threads must self-report via AddLocalThreadStats() (the THREAD_STATS_ADHOC collection policy); on Windows the built-in monitoring thread can sample every thread centrally.
Definition in file ThreadManager.h.