Boost logo

Boost Users :

Subject: Re: [Boost-users] ASIO Tutorial 5 - Synchronising handlers in a multithreaded programs - Doesn't use both threads for processing
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-05-16 20:22:04


AMDG

mark wrote:
> 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.

Sure. For such a tiny program there is no guarantee that the work will be
split evenly between threads. If there were enough work to keep both
the threads busy then they would both be used, but in this program, both
threads spend all their time waiting for the timer.

In Christ,
Steven Watanabe


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