Hannes Wengenroth
2012-06-29 08:15:58 UTC
Hi,
I'm making heavy use of strands for my project and stumbled over an implementation detail that I was unaware of.
I was relying on the order guarantees outlined in the docs (http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/reference/io_service__strand.html)
As far as I can see the call stack for immediate execution is based on the (shared) impl_ pointer of the strand, not on the object itself. So when the documentation says "performed outside the strand" it precisely means "performed outside any strand with the same implementation" (or, for practical purposes: "outside of any strand at all")
Did I get that right and is this the intended behavior? (ie in favor of dispatch performance)
If so, I think it would be nice to update the docs to be more explicit about what "performed outside the strand" actually means.
I've added a simplified example of my confusion below.
Cheers,
Hannes
void foo(const char * _pStr)
{
printf(_pStr);
}
void bar(boost::asio::strand& _rStrand)
{
_rStrand.post(boost::bind(&foo, "first"));
_rStrand.dispatch(boost::bind(&foo, "second"));
}
void main()
{
boost::asio::io_service ios;
boost::asio::strand A(ios);
boost::asio::strand B(ios);
bar(A); //order guaranteed
B.dispatch(boost::bind(&bar, A)); //order will be reversed if A and B share their implementation
}
I'm making heavy use of strands for my project and stumbled over an implementation detail that I was unaware of.
I was relying on the order guarantees outlined in the docs (http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/reference/io_service__strand.html)
As far as I can see the call stack for immediate execution is based on the (shared) impl_ pointer of the strand, not on the object itself. So when the documentation says "performed outside the strand" it precisely means "performed outside any strand with the same implementation" (or, for practical purposes: "outside of any strand at all")
Did I get that right and is this the intended behavior? (ie in favor of dispatch performance)
If so, I think it would be nice to update the docs to be more explicit about what "performed outside the strand" actually means.
I've added a simplified example of my confusion below.
Cheers,
Hannes
void foo(const char * _pStr)
{
printf(_pStr);
}
void bar(boost::asio::strand& _rStrand)
{
_rStrand.post(boost::bind(&foo, "first"));
_rStrand.dispatch(boost::bind(&foo, "second"));
}
void main()
{
boost::asio::io_service ios;
boost::asio::strand A(ios);
boost::asio::strand B(ios);
bar(A); //order guaranteed
B.dispatch(boost::bind(&bar, A)); //order will be reversed if A and B share their implementation
}