DelegateMQ
Loading...
Searching...
No Matches
Thread.h File Reference

Win32 API implementation of the DelegateMQ IThread interface. More...

#include "delegate/IThread.h"
#include "./predef/util/Timer.h"
#include "ThreadMsg.h"
#include <queue>
#include <atomic>
#include <optional>
#include <string>

Go to the source code of this file.

Classes

struct  ThreadMsgComparator
 
class  Thread
 Cross-platform thread for any system supporting C++11 std::thread (e.g. Windows, Linux). More...
 

Detailed Description

Win32 API implementation of the DelegateMQ IThread interface.

See also
https://github.com/endurodave/DelegateMQ David Lafreniere, 2025.

This class provides a Windows-native implementation of the IThread interface using Win32 synchronization primitives (CRITICAL_SECTION, CONDITION_VARIABLE, HANDLE). It creates a dedicated worker thread with an event loop capable of processing asynchronous delegates and system messages.

Key Features:

  • Priority Queue: Uses std::priority_queue to ensure high-priority delegate messages (e.g., system signals) are processed before lower-priority ones.
  • Back Pressure: Supports a configurable maxQueueSize. If the queue is full, DispatchDelegate() blocks the caller until space is available, preventing memory exhaustion.
  • Watchdog Integration: Includes a built-in heartbeat mechanism. If the thread loop stalls (deadlock or infinite loop), the watchdog timer detects the failure.
  • Synchronized Start: Uses a Win32 manual-reset event to ensure the thread is fully initialized and running before CreateThread() returns.
  • Debug Support: Sets the native thread name via SetThreadDescription() to aid debugging in Visual Studio.