C++ Thread

Introduction

The C++ Thread project is the snap_thread.cpp/.h moved in its own project.

We also will include any multi-thread related code to this project as we find it in our other libraries.

The project allows for easy thread manipulation and communication which makes it really easy to add multitasking to your projects. It also includes a thread pool with workers which we want to ameliorate to allow for concurrent programming rather than parallel programming, very much based on the Go environment.

Features

The library includes many sub-classes (which are to be broken up in main classes.)

We offer a FIFO like class to communicate between threads.

There is a mutex class and a way to lock/unlock on your stack.

The thread class is not the thread itself, we have a separate runner. This allows for safe in RAII. That is, when the thread goes out of scope and the runner is still running, everything still works exactly as expected: the thread sends a stop signal to the thread and deletes the runner object only once we join with the thread.

The pool object allows you to have many threads to run one task in parallel.

(Coming:) The concurrent pool, where we have a limited number of threads which run tasks. You can add and remove tasks at will. Depending on the number of tasks that need to be worked on and the number of CPUs we may increase the number of threads to handle the load.

Download

The source is available on github in our project git.

On Ubuntu, you may want to install it from our Snap! C++ Launchpad PPA. In that case, add the repository this way:

sudo add-apt-repository ppa:snapcpp/ppa
sudo apt-get update

Then install one of the library packages with the install command:

sudo apt-get install libcppthread
sudo apt-get install libcppthread-dev
sudo apt-get install libcppthread-doc

List of currently available Snap! C++ packages.

Support

You got a problem with the library? An idea to improve it? Please post a ticket in the Support area of Github.

Documentation

Check out our List of References.

License

The library is covered by the GPL v2 license. If you need a different license to integrate our projects in your software, feel free to contact us.

Changes

This code was first created in the snapwebsites library as the snap_thread.cpp and snap_thread.h files. It was moved to its own project because (1) it is actually pretty big already and (2) the library is very useful to other detacthed projects.

  • Version 1.0.0
    • First extraction from the snapwebsites library
Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly