Basic thread management

We are going to implement the thread class to give the user a sense of abstraction of the thread's implementation, which is useful for a specific problem. We will implement another helper class CLock, which we will use for synchronized execution if needed.

Getting ready

Make sure that Visual Studio is up and running.

How to do it...

Now, let's create our program and explain its structure using the following steps:

  1. Create a new empty C++ Console application named CThread.
  2. Add a new header file named CThread.h.
  3. Add the following code to it:
    #ifndef _CTHREAD_ #define _CTHREAD_ #include <windows.h> #define STATE_RUNNING 0x0001 #define STATE_READY 0x0002 #define STATE_BLOCKED 0x0004 #define STATE_ALIVE 0x0008 #define STATE_ASYNC 0x0010 ...

Get C++ Multithreading Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.