Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-08-27 13:23:03


Hi,

just implement an internal mapping of thread id to thread pointer. It can be
an unordered_map or stl::map, depends on how many threads you are going to
manage.

Just a small addition to you code:

On Wed, Aug 27, 2008 at 7:06 PM, Christian Ost <christian.ost_at_[hidden]>wrote:

> Hi,
>
> I have a question concerning the removal from entries of a thread_group.
> Consider the following code (i am working on a small threaded server):
>
> in TCPServer.h:
>
> boost::thread_group threads
>
> in TCPServer.cpp:
>
> int TCPServer::loop(int listen_fd) {
> for (;;) {
> [connect client]
> boost::thread* thrd = new
> boost::thread(boost::bind(&TCPServer::readMessages, this, rfd));
> threads.add_thread(thrd);

this can be written:
boost::thread* thrd =
threads.create_thread(boost::bind(&TCPServer::readMessages, this, rfd));
Here you don't need to call add_thread...

> ...

Regards,
Ovanes



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net