Boost logo

Boost :

Subject: Re: [boost] Boost Asio io_service as global?
From: Jinqiang Zhang (jasonzha_at_[hidden])
Date: 2011-07-19 23:00:27

your question is not relevant to boost::asio. You question is a design

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.
On Wed, Jul 20, 2011 at 11:23 AM, Philip Bennefall <philip_at_[hidden]>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:

Boost list run by bdawes at, gregod at, cpdaniel at, john at