Свободно компилируется на WATCOM C++, имеет минимальный код для запуска, остановки. Можно спокойно использовать как шаблон для много поточных программ.
#pragma once #include "stdafx.hpp" class FileMonitor { HANDLE hThreadEvent; HANDLE hThread; DWORD ThreadWorker(); static DWORD WINAPI cbThreadWorker(LPVOID lpParam); public: FileMonitor(); ~FileMonitor(); void Start(); void Stop(); };
#include "FileMonitor.hpp" FileMonitor::FileMonitor() { // Thread event hThreadEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if ( hThreadEvent == NULL ) { return; } } DWORD WINAPI FileMonitor::cbThreadWorker(LPVOID lpParam) { return reinterpret_cast<FileMonitor*>(lpParam)->ThreadWorker(); } DWORD FileMonitor::ThreadWorker() { while ( WaitForSingleObject(hThreadEvent, 0) != WAIT_OBJECT_0 ) { MessageBox(0, L"", L"Thread event", MB_ICONINFORMATION); Sleep(10000); } return ERROR_SUCCESS; } FileMonitor::~FileMonitor() { CloseHandle(hThreadEvent); free(home); } void FileMonitor::Start() { hThread = CreateThread(NULL, 0, cbThreadWorker, this, 0, NULL); } void FileMonitor::Stop() { SetEvent(hThreadEvent); WaitForSingleObject(hThread, INFINITE); }