Leon Mergen wrote:
Hello everyone,
I'm currently attempting to create a thread within a thread, and for some reason, the constructor seems to block and things just don't work very well.
Consider a class ``BackupHandler'' and a class ``BackupHandlerThread'' - the thread is created for once in the 50ms polling to an output file which might be used by other processes. Now, in BackupHandler, I do this:
--- boost::thread thread ( BackupHandlerThread (this->backupFile, this->data) ); ---
Which, as far as I am aware of, should first create a BackupHandlerThread object, and then "launch" the thread with this object. Now, since I print out some debug info, it seems like it reaches the BackupHandlerThread constructor once, and the destructor twice. <snip>
This calls the constructor you expected once, and then the copy constructor as well. If you don't want the BackupHandlerThread to be copied, I think you need to construct it other than as a temporary and pass a reference wrapper (boost::ref<BackupHandlerThread>) to the thread constructor. Ben.