MACE  1.0.0
 All Classes Namespaces Files Functions Variables Enumerations Defines
Public Member Functions | Static Public Member Functions | Friends
mace::cmt::thread Class Reference

manages cooperative scheduling of tasks within a single operating system thread. More...

#include <thread.hpp>

List of all members.

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 threadcurrent ()
static threadcreate (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 &)

Detailed Description

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.

Todo:
perform 'garbage collection' on idle stacks, perhaps before entering a blocking wait. Idle stacks would be any stack that is 'ready' and not blocking and would simply take turns processing new tasks.

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.


Member Function Documentation

template<typename Functor >
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.

Parameters:
fthe operation to perform
priothe priority relative to other tasks
na 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.

Todo:
this method currently blocks the calling thread while a new thread is created. It should return a future<thread*> instead.
static thread& mace::cmt::thread::current ( ) [static]

Returns the current thread.

Process tasks until thread::quit() is called.

Returns:
true unless quit() has been called.
template<typename Functor >
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.

Parameters:
fthe method to be called
priothe priority of this method relative to others
when- determines when this call will happen, as soon as possible after when
na debug name to be associated with this task.

Definition at line 122 of file thread.hpp.

template<typename Functor >
void mace::cmt::thread::post ( Functor &&  f,
priority  p = priority() 
) [inline]

Calls function f in this thread. Returns immediately.

Parameters:
p- the priority of a task.
t- the task to be run.

Definition at line 135 of file thread.hpp.

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.

Todo:
make quit non-blocking of the calling thread by eliminating the call to boost::thread::join
template<typename Functor >
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.

Parameters:
fthe method to be called
priothe priority of this method relative to others
whendetermines when this call will happen, as soon as possible after when
na debug name to be associated with this task.

Definition at line 81 of file thread.hpp.


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