-
Notifications
You must be signed in to change notification settings - Fork 1
multithreading
senso edited this page Jun 22, 2026
·
2 revisions
#example #threading #advanced
Thread creation and synchronization with critical sections.
| Module Name | multithreading |
| Type | mtSimple |
| Color | clDataModuleColor |
| Source | examples/MultiThreading/ |
Demonstrates how to create threads and protect shared data with critical sections. Includes a RAII-style CriticalSectionGuard helper for safe locking.
| # | Name | Type | I/O | Callback |
|---|---|---|---|---|
| 0 | output |
ptArray |
Output | None |
-
onInitModule: Creates a critical section (sdkCriticalSectionCreate) and two threads (sdkThreadCreate) that run every 100ms - Thread functions: Each thread locks the critical section, traces a message, then unlocks
-
Destructor: Destroys threads (
sdkThreadDestroy) and critical section (sdkCriticalSectionDestroy)
class CriticalSectionGuard
{
TCriticalSectionPtr cs;
public:
CriticalSectionGuard(TCriticalSectionPtr cs) : cs(cs)
{
sdkCriticalSectionLock(cs, 1000); // 1s timeout
}
~CriticalSectionGuard()
{
sdkCriticalSectionUnLock(cs);
}
};
// Usage:
void processThread(void* pModule, TThreadPtr thread)
{
auto* module = static_cast<MultiThreading*>(pModule);
CriticalSectionGuard guard(module->criticalSection);
// ... safe access to shared data ...
}-
sdkThreadCreatewith periodic interval (100ms) -
sdkCriticalSectionCreate/Lock/UnLock/Destroyfor mutex-like protection - RAII pattern for exception-safe critical section management
- Static thread callback with module pointer passed as context
-
DontProcess = TRUE— no audio processing
onGetModuleInfo · onGetNumberOfParams · onAfterQuery · onInitModule · onGetParamInfo · onCallBack
- RingModMultithread — Multi-threaded audio processing
- BackgroundJob — Background task execution