Phil Endecott wrote:
Yes, that's true. I suppose I'm thinking this way because I'm also imagining that I can subclass this new Thread class to add state, e.g.
class DaemonThread: public Thread { private: ... per-connection state ...
public: DaemonThread(int connection_fd); };
void mainloop() { while(1) { int fd = accept_connection_on_socket(); DaemonThread* handler = new DaemonThread(fd); } }
Try something along the lines of: class DaemonThread { private: int cfd_; public: explicit DaemonThread( int connection_fd ): cfd_( connection_fd ) {} void run() { /* thread procedure */ } }; void mainloop() { while( 1 ) { int fd = accept(); boost::shared_ptr<DaemonThread> handler( new DaemonThread( fd ) ); boost::thread th( boost::bind( &DaemonThread::run, handler ) ); } }