
On Fri, Dec 27, 2024 at 8:33 PM Georg Gast via Boost
Hi, If I use a asio::strand and post() there multiple function objects, are they executed in the same order or is the order of execution not specified?
I think to use it as a work queue but I need them to be processed in sequence...
Depending on your definition of "processed in sequence", a strand may or may not be what you're looking for. Strands are first-in-first-out but if your function objects are async in the Asio sense, you'll run into problems here. Each item in the strand will run in post() order until either it completes or it calls a non-blocking Asio function, which means you can have interwoven function objects executing "out of sequence". Strands are also for the multi-threaded io_contexts, to give safe access to I/O objects. If you need just a plain FIFO work queue, Asio has some thread pool classes you can use. If you need to sequence a bunch of async function objects, you'll need something different. - Christian