Git Product home page Git Product logo

Comments (5)

romange avatar romange commented on May 30, 2024

why should it be saying not-valid?
Boost.Fibers adopts a non-intrusive design where fibers scheduler is initialized when the fibers code is first called.

boost::this_fiber::get_id() calls internally boost::fibers::context::active() which does such one-time initialization when it is called in a new thread. the main thread is not different in this sense.

In short, you can use fibers from your main function and your main function becomes one of the fibers just because the scheduler must return to it when other fibers yield or are blocked on something.

if you read my post about fibers https://www.romange.com/2018/12/15/introduction-to-fibers-in-c-/
you could test it by copying the example below from the blog into your main function. fb1.join(); is a blocking condition for a main fiber where fiber scheduler switches the control to other fibers and then eventually switches back. The same true with fb2.

int keep_going = true;
int iteration = 1;
fibers::mutex mu;
fibers::conditional_variable cv;

auto cb = [&] {
  while (keep_going) {
    do_something_fiber_blocking();
    ++iteration;
    cv.notify_on();
  }
};

fiber fb1(cb);
fiber fb2([&] {
  {
    std::unique_lock<fibers::mutex> lock(mu);
    cv.wait(lock, [&] { return iteration > 5;});
  }
  keep_going = false;
});

fb1.join();
fb2.join();

from gaia.

akseg73 avatar akseg73 commented on May 30, 2024

from gaia.

akseg73 avatar akseg73 commented on May 30, 2024

I think i understand your point now. fibers are initialized the first time you utilize them. So if you don't utilize the fiber functionality then that code is not running fibers. Got it. I think then i know what to do.

Thanks a lot for the help.

from gaia.

akseg73 avatar akseg73 commented on May 30, 2024

from gaia.

romange avatar romange commented on May 30, 2024

I did not have any problem with fibers in that sense. I can see my functions inside fibers when doing profiling with gperftools @akseg73

from gaia.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.