Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <process.h>
- #include <cassert>
- #include <tchar.h>
- #include <stdlib.h>
- #include <stdio.h>
- //////////////////////////////////////////////////////////////////////////
- template <class Func>
- static void __cdecl WorkerThreadProc(void* pData) {
- assert(pData != nullptr);
- Func* pFunc = static_cast<Func*>(pData);
- (*pFunc)(); // Execute the task.
- delete pFunc; // Clean up.
- }
- //////////////////////////////////////////////////////////////////////////
- template <class Func>
- static void BeginThread(Func fn) {
- Func* pFn = new Func(fn);
- if (_beginthread(WorkerThreadProc<Func>, 0, pFn) == -1L) {
- errno_t err;
- _get_errno(&err);
- assert(false);
- delete pFn; // Clean up.
- }
- }
- //////////////////////////////////////////////////////////////////////////
- int main(int, char**)
- {
- printf_s("CTRL-C to quit:n");
- while (true) {
- BeginThread( []()->void{} ); // Launch worker to execute task.
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment