cpp-pthread  (v1.7.3)
Simple C++ wrapper to pthread functions.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
Public Member Functions | List of all members
pthread::thread Class Reference

#include <thread.hpp>

Public Member Functions

 thread ()
 
 thread (const runnable &runner, const std::size_t stack_size=0)
 
 thread (thread &&other)
 
 thread (const thread &)=delete
 
virtual ~thread ()
 
void join ()
 
bool joinable () const
 
int cancel ()
 
thread_status status ()
 
threadoperator= (const thread &)=delete
 
threadoperator= (thread &&other)
 

Detailed Description

Handles POSIX (Portable Operating System Interface) threads.


    class reader_thread: public runnable {
    public:
      void run() {...}
    };
    reader_thread rt;
    thread t{rt};
    t.join();
Author
herbert koelman (herbe.nosp@m.rt.k.nosp@m.oelma.nosp@m.n@me.nosp@m..com)

Definition at line 91 of file thread.hpp.

Constructor & Destructor Documentation

pthread::thread::thread ( )

create a new thread status is no_a_thread

Definition at line 76 of file thread.cpp.

pthread::thread::thread ( const runnable runner,
const std::size_t  stack_size = 0 
)

create a new thread

The new thread is made runnable, and will start executing the run routine, with.

Parameters
runnera class that implements the runnable interface.
stack_sizethread stack size in bytes (default is 0 and means use default stack size)

Definition at line 81 of file thread.cpp.

pthread::thread::thread ( thread &&  other)

Move contructor.

once moved this not a thread anymore. Status is thread_status::not_a_thread

Parameters
otherthread that will be moved, on completion other is no longer a thread.

Definition at line 110 of file thread.cpp.

pthread::thread::thread ( const thread )
delete

Copy constructor is flagged deleted because it makes no sense to copy a thread.

pthread::thread::~thread ( )
virtual

cleanup thread ressources.

Definition at line 115 of file thread.cpp.

Member Function Documentation

int pthread::thread::cancel ( )

The cancel method requests the cancellation of the thread. The action depends on the cancelability of the target thread:

  • If its cancelability is disabled, the cancellation request is set pending.
  • If its cancelability is deferred, the cancellation request is set pending till the thread reaches a cancellation point.
  • If its cancelability is asynchronous, the cancellation request is acted upon immediately; in some cases, it may result in unexpected behaviour.

The cancellation of a thread terminates it safely, using the same termination procedure as the pthread_exit subroutine.

Definition at line 59 of file thread.cpp.

void pthread::thread::join ( )

The join method blocks the calling thread until the thread terminates. The target thread's termination status is returned in the status parameter.

If the target thread is already terminated, the method returns immediately.

This method does not itself cause a thread to be terminated.

Exceptions
pthread_exceptionif this is not a thread or if thread_id == this_thread::get_id().

Definition at line 26 of file thread.cpp.

bool pthread::thread::joinable ( ) const
inline
Returns
true if this thread can be joined.

Definition at line 139 of file thread.hpp.

thread& pthread::thread::operator= ( const thread )
delete

copy operator is flagged deleted, copying doesn't make sense

thread & pthread::thread::operator= ( thread &&  other)

move a thread to another thread.

Parameters
otherthread to move, on completion it is not a thread anymore (thread_status::not_a_thread).
Returns
a thread

Definition at line 120 of file thread.cpp.

thread_status pthread::thread::status ( )
inline
Returns
the status of the thread (thread::status).

Definition at line 156 of file thread.hpp.


The documentation for this class was generated from the following files: