the following code:
/***************************************************************************/
boost::mutex m;
struct func {
func(int v):n(v) {}
void operator()() {
{ boost::mutex::scoped_lock l(m);
std::cout << "run function " << n << std::endl;
}
for ( int idx = 0; idx < 4; ++idx ) {
{ boost::mutex::scoped_lock l(m);
std::cout << "function " << n << ", ping " << idx << std::endl;
}
sleep(1);
}
}
private:
int n;
};
/***************************************************************************/
int main(int argv, const char** argc) {
boost::asio::io_service io;
for ( int idx = 0; idx < 4; ++idx ) {
io.post(func(idx));
}
std::cout << "before run" << std::endl;
io.poll();
std::cout << "after run" << std::endl;
std::cin.get();
return 0;
}
/***************************************************************************/
gives such an output:
**before run**
run function 0
function 0, ping 0
function 0, ping 1
function 0, ping 2
function 0, ping 3
run function 1
function 1, ping 0
function 1, ping 1
function 1, ping 2
function 1, ping 3
run function 2
function 2, ping 0
function 2, ping 1
function 2, ping 2
function 2, ping 3
run function 3
function 3, ping 0
function 3, ping 1
function 3, ping 2
function 3, ping 3
**after run**
but, according to the documentation:
The poll() function runs handlers that are ready to run, without blocking, until the io_service has been stopped or there are no more ready handlers.
poll() - is a non-blocking method. what's the problem?
and the second question: in documentation it is said that:
return The number of handlers that were executed.
if it is non-blocking, what value it will return? - the number of objects in the queue? - but this is not the same thing as "that were executed".