
your question is not relevant to boost::asio. You question is a design question: Should a frequent-accessed variable being global? My taste to your question is: I don't like global variable, so I would like to pass the reference around. jinqiang On Wed, Jul 20, 2011 at 11:23 AM, Philip Bennefall <philip@blastbay.com>wrote:
Hi all,
I am just beginning to learn how to use Boost Asio in a multithreaded environment, and one thing struck me when looking at the various examples. I have not been able to find an answer to this in the documentation, but in case it is explained somewhere that I've missed I apologize in advance.
Taking the asynchronous echo server as my base I am writing a multithreaded server that handles connections in a thread pool. My question is simply, why is the io_service object always passed around between class instances as a reference in the constructor? Why can one not store it as a global variable? I cannot see how this makes a difference, and a global seems to make things a lot easier. Is there a particular reason why I should not do this?
Thanks in advance for any help.
Kind regards,
Philip Bennefall _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost