This topic is 4895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi! I was checking out Boost Threads as an alternative to my current multithreading system, but I can't seem to find a way to send an argument to a thread when joining it (i.e CreateThread procedure). I've taken a look in the docs (admittedly sloppely) and was not able to find anything of the sort. I would be grateful if someone could confirm whether this is possible and perhaps direct me to were I could find help on the specifications for this. Thanks in advance Regards, /Omid EDIT:: TYPO [Edited by - Omid Ghavami on July 20, 2005 2:09:42 PM]

Share on other sites
Err, in creating or joining?

When creating, the power lies in the fact that boost::thread's constructor takes a boost::function< void( void ) >, which can in fact be constructed from a function which takes arguments, bound. Working example:

#include <string>#include <iostream>#include <boost/thread.hpp>#include <boost/bind.hpp>void hello ( std::string target ) {    std::cout << "Hello, " << target << std::endl;}int main() {    boost::thread do_hello_world( boost::bind( &hello , "world" ) );    do_hello_world.join(); //dont terminate program before thread completes}

Results in:
Hello, world

Hope this helps :-).

Share on other sites
Ah! Just what I was looking for!
Seems I got the terminology a bit mixed up hehe

Thanks for the help MaulingMonkey :)

Regards,
/Omid

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633705
• Total Posts
3013464
×