Boost logo

Boost Users :

Subject: Re: [Boost-users] Does io_service::post() block while io_service isbusy?
From: Andrew Holden (aholden_at_[hidden])
Date: 2012-04-13 14:14:26


On Thursday, April 12, 2012 10:02 AM, Andreas Wehrmann wrote:
> The question is:
> When the worker thread is currently executing work (of which
> there may be a lot) which the high priority thread previously
> posted to it, is the io_service locked?; so that calls to
> io_service::post() block until the io_service is done?

No. io_service::post will not block until the previous work items are
done.

> I came to this question because I saw that in ::post() there
> is a lock involved protecting access to the operations queue.

Although I'm not an expert of asio, I suspect io_service::run holds that
lock for very short periods. Probably similar to the following
pseudocode:

1: Wait until an operation is in the queue.
2: Acquire the lock.
3: Try to remove an operation from the operations queue. Don't wait if
another thread already removed it between steps 1 and 2.
4: Release the lock.
5: Run the operation if we got one.


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