|
Boost Users : |
Subject: Re: [Boost-users] boost::asio blocking socket read with timeout with multiple threads
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2018-03-20 20:31:33
On 21/03/2018 03:16, Thomas Quarendon wrote:
> On Linux you can do that, since you can create an anonymous pipe
> easily and wrap it with asio. You can't create anonymous pipes on
> Windows though, so you have to create named pipes in the operating
> system, which is going to add overhead. What you would *really* want
> is a fully user mode pipe implemented purely within asio and not
> going down to the kernel at all, apart from use of mutex and
> condition variable. But then I've just invented zeromq.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365152.aspx
There are even ways to pass anonymous pipe handles explicitly to another
already-running process (with cooperation on both sides), which I don't
think is possible in Linux.
Granted, this is still an OS pipe, but there isn't that much overhead,
especially within a single process.
Still, there's no reason to create pipes for inter-thread communication.
You're in a shared memory space, and ASIO is itself a queued-task
management system, and you can store arbitrary state for each task
(including completely unique structures for each task, if you really
want). Just store the data you want to process directly in the object
that you're posting to the other io_service, then store the result in
the object that you post back for completion.
If you want to stick with a data-stream structure, you could use a
Boost.LockFree queue, or a regular queue protected by mutex, or any
other data structure that fits your purpose.
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