Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-07-14 03:12:59


On 14/07/2014 17:58, imran sheikh wrote:
> When I ran this piece of code on my machine I found that for every run 4
> threads are only used out of the pool. As I have 4 cores in my machine.
> Is it so??
[...]
> for(size_t i=0; i<boost::thread::hardware_concurrency(); i++) {
> group.create_thread(
> boost::bind(&boost::asio::io_service::run, &ioservice)
> );
> }

You're creating 4 threads for your pool. This should not surprise you.

> Also, my application is time-sensitive and I need to do some time
> measures. If I use sleep my results will be incorrect. So, please
> suggest an alternative way to get notified when all the threads
> finish without using sleep.

There isn't any obvious reason to call sleep in the code that you had to
begin with.

If you want to retrieve the individual results of each asynchronous task
rather than waiting for all tasks to complete, you might want to read up
on futures.


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