Jump to content
  • Advertisement
Sign in to follow this  
Omid Ghavami

Boost Threads

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

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!