Boost logo

Boost :

Subject: Re: [boost] [asio] Question regarding io_service.post() and pool of threads
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2010-09-28 05:15:06


On 2010-09-28 10:24, Romain CHANU wrote:
> Hi Vivek,
>
> I did a simple program that creates a pool of threads running
> io_service.run() and calling a function many times (through
> io_service.post() ) (like the simple program in the website given earlier).
>
> My function accesses / modifies an object (without lock) and the program
> just crashes.
>
> I am not really sure of the behavior of functions posted to io_service (i.e
> io_service.post() ) with multiple threads running io_service.run().
>
> Anyone?
>

if the io_service is running in a threadpool, handlers that are posted
may execute at any time from any thread. If you would like to run
handlers which access shared resources that need protection, you could
consider looking into Asio's strand facility.

Rutger


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk