|
cppthread 1.1.16
C++ Thread Library
|
An RAII class managing the lifetime of a thread. More...

Public Member Functions | |
| life (life const &rhs)=delete | |
| The copy operator is deleted. | |
| life (thread *const thread) | |
| Initialize a "thread life" object. | |
| ~life () | |
| Make sure the thread stops. | |
| life & | operator= (life const &rhs)=delete |
| The assignment operator is deleted. | |
Private Attributes | |
| thread * | f_thread = nullptr |
| The pointer to the thread being managed. | |
This class is used to manage the life of a thread: the time it runs. The constructor calls the thread::start() function and the destructor makes sure to call the thread::stop() function.
If you have a specific block or another class that should run a thread for the lifetime of the block or class object, then this is well adapted.
| cppthread::life::life | ( | thread *const | thread | ) |
This type of objects are used to record a thread and make sure that it gets destroyed once done with it.
The constructor makes sure that the specified thread is not a null pointer and it starts the thread. If the thread is already running, then the constructor will throw.
Once such an object was created, it is not possible to prevent the thread life destructor from calling the stop() function and waiting for the thread to be done.
| [in] | thread | The thread which life is to be controlled. |
Definition at line 87 of file life.cpp.
References f_thread, and cppthread::thread::start().

|
delete |
The life object holds a bare pointer to the thread it has to manage, so we have to declare a copy operator to explicitly delete the copy operator. We could not have multiple instances of the life object anyway.
| [in] | rhs | The right hand side. |
| cppthread::life::~life | ( | ) |
This function requests that the attach thread stop. It will block until such happens. You are responsible to make sure that the stop happens early on if your own object needs to access the thread while stopping.
Definition at line 111 of file life.cpp.
References f_thread, and cppthread::thread::stop().

|
delete |
The life object holds a bare pointer to the thread it has to manage so we have to declare an assignment operator to explicitly delete the operator. We could not have multiple instances of the life object anyway.
| [in] | rhs | The right hand side. |
|
private |
This pointer is a pointer to the thread. Once a thread life object is initialized, the pointer is never nullptr (we throw before in the constructor if that is the case.)
The user of the life class must view the thread pointer as owned by the life object (similar to a smart pointer.)
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.