O'Reilly logo

C++ Multithreading Cookbook by Milos Ljumovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required