Boost logo

Boost Users :

Subject: [Boost-users] ASIO Tutorial 5 - Synchronising handlers in a multithreaded programs - Doesn't use both threads for processing
From: mark (markcsu_at_[hidden])
Date: 2009-05-16 03:54:39


Using the code from
http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/tutorial/tuttimer5.html
with a few extra cout's for extra info.

If you print out the thread IDs of at the start of print1 and print2 you'll
see that both methods are actually using the same thread. ie two threads
gets created but only one does any work.

I'm printing the thread ID's via
std::cout << "print1 " << boost::this_thread::get_id() << std::endl;
std::cout << "print2 " << boost::this_thread::get_id() << std::endl;

at the top of print 1 and print 2.

I first noticed this when I was single line stepping through the code trying
to work out how the second thread could possibly be doing anywork since
t.join() is called after io.run(). Also if I comment out io.run() the
program still works the same as before, except its the second thread doing
all the processing.

Compiler MSVC 9.0, happens on both debug and release.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net