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.