Boost logo

Boost Users :

From: Christian Ost (christian.ost_at_[hidden])
Date: 2008-08-27 13:06:50


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);
    }
  }
}

int TCPServer::readMessages(int rfd) {
  boost::this_thread::at_thread_exit(boost::bind(&TCPServer::exitThread, this));
  for(;;) {
    [read message]
    if ([buffer is empty]) {
      [close connection]
      return(0);
    }
  }
  return 1;
}

void TCPServer::exitThread() {
  cout << "thread exited" << endl;
}

Now I would like to remove the exited thread from the thread_group,
however to do this
I would need its thread* object - but the maximum of information I can get from
boost::this_thread is a boost::thread::id and I haven't found a
possibility to get a thread
by its thread::id so far.

How can/should I solve this issue?
I would be quite happy about any advice...

Thank you very much!

Christian


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