manages cooperative scheduling of tasks within a single operating system thread. More...
#include <thread.hpp>
Public Member Functions | |
| const char * | name () const |
| returns the name given by set_name() for this thread | |
| void | set_name (const char *n) |
| associates a name with this thread. | |
| template<typename Functor > | |
| auto | schedule (Functor &&f, const system_clock::time_point &when, priority prio=priority())-> future< decltype(f())> |
| template<typename Functor > | |
| auto | async (Functor &&f, priority prio=priority())-> future< decltype(f())> |
| template<typename Functor > | |
| void | post (Functor &&f, const system_clock::time_point &when, priority prio=priority()) |
| template<typename Functor > | |
| void | post (Functor &&f, priority p=priority()) |
| void | quit () |
| void | exec () |
| bool | is_running () const |
| priority | current_priority () const |
Static Public Member Functions | |
| static thread & | current () |
| static thread * | create (const char *name="") |
Friends | |
| class | thread_private |
| class | mutex |
| class | promise_base |
| void | mace::cmt::yield () |
| void | mace::cmt::usleep (uint64_t) |
| void | mace::cmt::sleep_until (const system_clock::time_point &) |
When ever a task must wait, a new stack is created that continues to process events. These stacks will not be deallocated, but instead stand ready to be re-used the next time a new stack is required.
This means that the total number of stacks in use for a given thread will grow to the maximum number of simultaniously waiting asynchronous operations.
These todo items may be ignored so long as you use 'long-lived' threads and keep the maximum number of simultanous 'blocked' tasks to something reasonable.
Definition at line 44 of file thread.hpp.
| auto mace::cmt::thread::async | ( | Functor && | f, |
| priority | prio = priority() |
||
| ) | [inline] |
Calls function f in this thread and returns a future<T> that can be used to wait on the result.
| f | the operation to perform |
| prio | the priority relative to other tasks |
| n | a debut name to associate with this task. |
Definition at line 101 of file thread.hpp.
| static thread* mace::cmt::thread::create | ( | const char * | name = "" | ) | [static] |
Creates a new thread with the given name.
| static thread& mace::cmt::thread::current | ( | ) | [static] |
Returns the current thread.
| void mace::cmt::thread::exec | ( | ) |
Process tasks until thread::quit() is called.
| bool mace::cmt::thread::is_running | ( | ) | const |
| void mace::cmt::thread::post | ( | Functor && | f, |
| const system_clock::time_point & | when, | ||
| priority | prio = priority() |
||
| ) | [inline] |
Performs f() asynchronously at the specified time without returning a future. This is slightly more effecient as there is no need to allocate a promise object.
| f | the method to be called |
| prio | the priority of this method relative to others |
| when | - determines when this call will happen, as soon as possible after when |
| n | a debug name to be associated with this task. |
Definition at line 122 of file thread.hpp.
| void mace::cmt::thread::post | ( | Functor && | f, |
| priority | p = priority() |
||
| ) | [inline] |
Calls function f in this thread. Returns immediately.
| p | - the priority of a task. |
| t | - the task to be run. |
Definition at line 135 of file thread.hpp.
| void mace::cmt::thread::quit | ( | ) |
This method will cancel all pending tasks causing them to throw cmt::error::thread_quit.
If the current thread is not this thread, then the current thread will wait for this thread to exit.
This is a blocking wait via boost::thread::join and other tasks in the current thread will not run while waiting for this thread to quit.
boost::thread::join | auto mace::cmt::thread::schedule | ( | Functor && | f, |
| const system_clock::time_point & | when, | ||
| priority | prio = priority() |
||
| ) | [inline] |
Calls function f in this thread and returns a future<T> that can be used to wait on the result.
| f | the method to be called |
| prio | the priority of this method relative to others |
| when | determines when this call will happen, as soon as possible after when |
| n | a debug name to be associated with this task. |
Definition at line 81 of file thread.hpp.
1.8.0