|
Boost Users : |
Subject: Re: [Boost-users] Understanding fibers
From: Stephan Menzel (stephan.menzel_at_[hidden])
Date: 2018-12-14 12:37:47
Well, I should have just tried rather than asking questions.
On Fri, Dec 14, 2018 at 8:33 AM Stephan Menzel <stephan.menzel_at_[hidden]>
wrote:
>
> If I simply add fiber futures to the interface, can I set the value to the
> fiber promise in that other thread running the io_service, leaving the
> basic architecture? This would allow me to still use the library with
> regular threading and in non-fiber scenarios, which I would very much like
> to. Alternatively, I could just hand in a callback with a fiber promise but
> this also means that the callback is executed in the thread that runs the
> client object. Hence my question.
>
I have just tried and wrote a little quick and dirty testcase. I have the
results here, in case anyone is interested:
https://github.com/MrMoose/mredis/blob/master/fiber_testsuite.cpp
The code doesn't have any explicit yields(), which was important for me for
some reason and yet does as expected. My taking away from this exercise are:
* Yes it is possible to set the value of a fiber promise in another
thread. At least I didn't see problems.
* When I use the callback mechanism, I can transform the code without
having to change the underlying library
* Fibers are not as complicated as I thought they would be.
Once I realized the interface is very similar to threads and everything
that would block (such as wait for the future to become ready) is pretty
much equivalent to 'hand over to another fiber' it all fell into place. I
do believe there could be a bit less intimidating examples in the docs
though. Perhaps something like 'fibers for people already familiar with
threads'... Turned out to be much less difficult than I thought.
Anyway, thanks again for your help. I am now equipped to use the fibers in
my async server.
Cheers,
Stephan
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