Boost 1.33 Thread Creation with arguments

Instead of using boost:thread(<Functionname>, <arg1>, … <argn>) we have to use boost:thread ThreadName(boost::bind(<Functionname>,arg1,…,argn))


void workerFunc(int i)
    boost::xtime t;
    t.sec += i;

    std::cout << "Worker: running, waiting "<< i << " seconds…" << std::endl;

    // Pretend to do something useful…

    std::cout << "Worker: wtime="<< i << " finished" << std::endl;

int main(int argc, char* argv[])
    std::cout << "main: startup" << std::endl;

    boost::thread workerThread(boost::bind(workerFunc,3));
    boost::thread workerThread2(boost::bind(workerFunc,5));

    std::cout << "main: waiting for thread" << std::endl;


    std::cout << "main: done" << std::endl;

    return 0;

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.