Guest User

Untitled

a guest
Jan 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <process.h>
  3. #include <cassert>
  4. #include <tchar.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. //////////////////////////////////////////////////////////////////////////
  9. template <class Func>
  10. static void __cdecl WorkerThreadProc(void* pData) {
  11. assert(pData != nullptr);
  12. Func* pFunc = static_cast<Func*>(pData);
  13. (*pFunc)(); // Execute the task.
  14. delete pFunc; // Clean up.
  15. }
  16. //////////////////////////////////////////////////////////////////////////
  17. template <class Func>
  18. static void BeginThread(Func fn) {
  19. Func* pFn = new Func(fn);
  20. if (_beginthread(WorkerThreadProc<Func>, 0, pFn) == -1L) {
  21. errno_t err;
  22. _get_errno(&err);
  23. assert(false);
  24. delete pFn; // Clean up.
  25. }
  26. }
  27. //////////////////////////////////////////////////////////////////////////
  28. int main(int, char**)
  29. {
  30. printf_s("CTRL-C to quit:n");
  31. while (true) {
  32. BeginThread( []()->void{} ); // Launch worker to execute task.
  33. }
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment