cqueues icon indicating copy to clipboard operation
cqueues copied to clipboard

Interop with Tarantool fibers

Open aleclarson opened this issue 7 years ago • 3 comments

Do you have any suggestions on getting cqueues to work seamlessly with Tarantool fibers?

I've interposed step like this, which lets me call :step and :loop within a fiber.

Now I'm trying to get cq.poll() to not cause a "yield across C-call boundary" error when called within a fiber.

I think the issue is that cq.running() doesn't return nil when within a fiber, which make sense. Unfortunately, that behavior makes this line and this line problematic. If those two lines did select(2, cq.running()), it would ensure the current coroutine is a cqueue before doing a native poll.

I may need to handle this by monkey-patching fiber.create, but I'm curious if a simpler solution exists with cqueues. In the end, it may be easiest (but less convenient) to avoid fibers within cqueues at all costs. Thanks!

aleclarson avatar Apr 27 '18 16:04 aleclarson

Another issue: yielding the parent fiber from within a cqueue is nasty business. The cqueue will still think it's running, when in reality its parent fiber is suspended. This makes the return value of core.running incorrect.

aleclarson avatar Apr 28 '18 20:04 aleclarson

At this point, I think forking cqueues to use fibers is the right solution. But I'd like some feedback on this issue first, if possible.

aleclarson avatar Apr 28 '18 21:04 aleclarson

On second thought, I think exposing Tarantool's scheduler so it can be driven with a cqueue could be a viable option. But maybe not, since coroutine.yield is used by cqueues, which Tarantool's scheduler may not like.

aleclarson avatar Apr 28 '18 21:04 aleclarson