|
Boost : |
From: Christian Mazakas (christian.mazakas_at_[hidden])
Date: 2024-12-30 17:43:26
On Mon, Dec 30, 2024 at 2:04â¯AM Richard Hodges via Boost <
boost_at_[hidden]> wrote:
> If you want to run composed operations sequentially (with respect to each
> other) then you must coordinate this yourself via an âasynchronous mutex or
> semaphoreâ.
>
> Asioâs timer object can be used as a semaphore :
> - set to max timeout
> - use cancel_one() to release the next job.
>
Asio seems to have thread-safe channels in its experimental namespace,
these would work as well.
To Richard's point, you're usually better off reaching for the channel
abstraction here because it actually does what you want, just more
straightforwardly.
Something like this: https://godbolt.org/z/8zxTPsbG4
You can emulate this using the techniques Richard alluded to as well. You
can use a timer like a condition variable and have your loop asynchronously
block on it via `.async_wait()` with the maximum timeout. Wakeups happen by
cancellation, which you'd ignore in your processing loop.
This enables you to trivially handle the case where processing work items
is an inherently asynchronous task composed of multiple I/O ops.
- Christian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk