Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Questions.(and About Using fiber.join) #129

Closed
sxysxy opened this issue Jun 4, 2017 · 1 comment
Closed

Some Questions.(and About Using fiber.join) #129

sxysxy opened this issue Jun 4, 2017 · 1 comment

Comments

@sxysxy
Copy link

sxysxy commented Jun 4, 2017

I use this boost-fiber in my game engine, and get these questions:

  1. Is it highly real-time?
  2. A problem... I uses fiber.join() as fiber.resume in ruby(enter the fiber and continue), uses boost::this_fiber::yield() as Fiber.yield in ruby(return to father fiber), and get wrong result, then I write a piece of code:
int main(){
    boost::fibers::fiber f([&] {
        while (true) {
            puts("ppp");
            boost::this_fiber::yield();
        }
    });
    while (true) {
        f.join()
        puts("qqq");
    }
    return 0;
}

As what I thinked, it should print as:

ppp
qqq
ppp
qqq
.......

But in fact it print:

ppp
ppp
ppp
ppp
....

It seems like boost::this_fiber::yield() does not return where the fiber was called.
What should I do? Thanks a lot, I am tired of 6 hours working on config boost and using fibers..

@sxysxy sxysxy changed the title Some Questions. Some Questions.(and About Using fiber.join) Jun 4, 2017
@olk
Copy link
Member

olk commented Jun 4, 2017

1.) no
2. ) API of boost.fiber is equivalent to std::thread

  • you can only join a fiber once (your example is wrong)
  • this_fiber::yield() does yield to another fiber, which fiber will be resumed next depends on the scheduling algorithm (round-robin etc.; it is a customization point) - it does not necessarily resume the father fiber. For instance if you use a scheduler that respects fiber priority, the next fiber that gets resumed is the one with the highest priority in the ready-queue.

I suggest to study the documentation of boost.fiber (contains examples) + the examples section.

@olk olk closed this as completed Jun 4, 2017
Romain-Geissler-1A pushed a commit to Romain-Geissler-1A/fiber that referenced this issue Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants