Boost logo

Boost Users :

Subject: Re: [Boost-users] ASIO HTTP Server 3 Example: sharing stack data between threads
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-05-23 14:22:14


AMDG

Aaron Riekenberg wrote:
> I was reading through the ASIO HTTP Server 3 example
> (http://tinyurl.com/35hwtd5) that uses a thread pool to call
> io_service::run.
>
> In both posix_main.cpp and win_main.cpp an http::server3::server
> object is created on the stack in main(). server has a
> boost::asio::io_service member (io_service_). main calls server::run,
> which creates a pool of threads that each call io_service_.run. So at
> this point the io_service_ object is within main's stack is being
> shared by multiple threads.
>

The threads can all access the memory fine, and the
io_service object won't be cleaned up until
all the threads are joined. There is no problem
here.

> Am I missing something or is this a bad thing to do and encourage
> others to copy? Seems like a simple fix would be to allocate the
> server object in main on the heap.
>

In Christ,
Steven Watanabe


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