25#ifndef __JOIN_THREAD_HPP__
26#define __JOIN_THREAD_HPP__
29#include <system_error>
57 template <
class Function,
class... Args>
58 explicit Invoker (Function&& func, Args&&... args)
59 : _func (
std::bind (
std::forward <Function> (func),
std::forward <Args> (args)...)),
62 pthread_attr_init (&_attr);
63 pthread_create (&_handle, &_attr, _routine,
this);
110 static void * _routine (
void * context);
116 void * routine (
void);
119 std::function <void ()> _func;
122 pthread_attr_t _attr;
128 std::atomic_bool _done;
150 template <class Function, class... Args>
151 explicit
Thread (Function&& func, Args&&... args)
152 : _invoker (new
Invoker (
std::forward <Function> (func),
std::forward <Args> (args)...))
197 bool running () const noexcept;
thread invoker class.
Definition thread.hpp:44
Invoker()=delete
default constructor.
Invoker(const Invoker &other)=delete
copy constructor.
Invoker & operator=(const Invoker &other)=delete
copy assignment.
Invoker(Invoker &&other)=delete
move constructor.
~Invoker()
destoyer.
Definition thread.cpp:38
thread class.
Definition thread.hpp:138
~Thread()
destroys the thread object.
Definition thread.cpp:96
bool tryJoin()
performs a nonblocking join on the running thread.
Definition thread.cpp:136
Thread() noexcept=default
default constructor.
Thread(const Thread &other)=delete
copy constructor.
void swap(Thread &other)
swap underlying handles of two thread objects.
Definition thread.cpp:163
Thread & operator=(const Thread &other)=delete
copy assignment.
void cancel()
cancel the running thread if any.
Definition thread.cpp:150
bool joinable() const noexcept
check if thread is joinable.
Definition thread.cpp:105
bool running() const noexcept
check if the thread is running.
Definition thread.cpp:114
Definition acceptor.hpp:32