Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class thread_group EXTENSION

Constructor
Destructor
Member function create_thread()
Member function add_thread()
Member function remove_thread()
Member function join_all()
Member function is_this_thread_in()
Member function is_thread_in()
Member function interrupt_all()
Member function size()
#include <boost/thread/thread.hpp>

class thread_group
{
public:
    thread_group(const thread_group&) = delete;
    thread_group& operator=(const thread_group&) = delete;

    thread_group();
    ~thread_group();

    template<typename F>
    thread* create_thread(F threadfunc);
    void add_thread(thread* thrd);
    void remove_thread(thread* thrd);
    bool is_this_thread_in();
    bool is_thread_in(thread* thrd);
    void join_all();
    void interrupt_all();
    int size() const;
};

thread_group provides for a collection of threads that are related in some fashion. New threads can be added to the group with add_thread and create_thread member functions. thread_group is not copyable or movable.

thread_group();

Effects:

Create a new thread group with no threads.

~thread_group();

Effects:

Destroy *this and delete all boost::thread objects in the group.

template<typename F>
thread* create_thread(F threadfunc);

Effects:

Create a new boost::thread object as-if by new thread(threadfunc) and add it to the group.

Postcondition:

this->size() is increased by one, the new thread is running.

Returns:

A pointer to the new boost::thread object.

void add_thread(thread* thrd);

Precondition:

The expression delete thrd is well-formed and will not result in undefined behaviour and is_thread_in(thrd) == false.

Effects:

Take ownership of the boost::thread object pointed to by thrd and add it to the group.

Postcondition:

this->size() is increased by one.

void remove_thread(thread* thrd);

Effects:

If thrd is a member of the group, remove it without calling delete.

Postcondition:

If thrd was a member of the group, this->size() is decreased by one.

void join_all();

Requires:

is_this_thread_in() == false.

Effects:

Call join() on each boost::thread object in the group.

Postcondition:

Every thread in the group has terminated.

Note:

Since join() is one of the predefined interruption points, join_all() is also an interruption point.

bool is_this_thread_in();

Returns:

true if there is a thread th in the group such that th.get_id() == this_thread::get_id().

bool is_thread_in(thread* thrd);

Returns:

true if there is a thread th in the group such that th.get_id() == thrd->get_id().

void interrupt_all();

Effects:

Call interrupt() on each boost::thread object in the group.

int size();

Returns:

The number of threads in the group.

Throws:

Nothing.


PrevUpHomeNext