Solution for handling boost::thread with member functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tdlr
    New Member
    • Jan 2011
    • 22

    Solution for handling boost::thread with member functions

    I'm using VC++ 2010 with Boost 1.43.
    I've just created a class that uses winsock to handle network communication. Now there's a method called "fillQueue" which is defined like this:
    Code:
    void fillQueue(NetworkQueueTS& nq);
    Problem is, the method enters an infinite while loop which fills the NetworkQueue with data. So it needs to be in an extra thread. The NetworkQueue class itself is already thread safe.

    Now when I want to start an additional thread at the beginning of my app, it needs to be something like a "fire and forget" function call. The thread must be created and needs to live until the program ends.

    I've tried the following:
    Code:
    boost::thread whatever(mySock->fillQueue, nq);
    whatever.detach();
    Obviously, this doesn't work, because fillQueue is a bound function. So now I'm looking for the fastest solution to do something like what I had in mind.

    TIA
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Can you not just call CreateThread using fillQueue as the thread?

    That way you can communicate with fillQueue during the program. fillQueue just needs a WaitForSingleOb ject inside the infinite whie loop.

    You can use events to terminate the thread.

    Comment

    Working...