Giter VIP home page Giter VIP logo

Comments (2)

edubart avatar edubart commented on May 24, 2024

Your test case does not contain enough to reproduce. But that is happening likely due to some misuse, moving implementation to a .cpp is allowed. Minicoro has been used and works with C++, just remember these caveats from main page:

Don't use coroutines with C++ exceptions, this is not supported.
When using C++ RAII (i.e. destructors) you must resume the coroutine until it dies to properly execute all destructors.

Some notes from your code:

  • mco_push can fail, you should check its return.
  • In ~CoroutineManager, take care letting a destructor destroy the coroutine this way, to properly destroy your coroutine and execute all destructors (smart pointers have destructors), you must be sure that everything pushed was poped and the coroutine is in dead state.

To help your development and catch mistakes early define MCO_DEBUG. Also if you are having random/odd issues perhaps you are getting stack overflow, increasing MCO_DEFAULT_STACK_SIZE to 1MB may help in this case.

from minicoro.

CPStagg avatar CPStagg commented on May 24, 2024

What pattern would be used to pass e.g. a std::shared_ptr into a coroutine function and use it successfully? The problem I'm having is that when I try to extract the shared_ptr from the stack, it seems to make a bitwise copy of the shared_ptr, rather than a constructed copy (and concomitant ref count increase), which creates two issues:

  1. If you create the original shared_ptr inside one scope, create the coroutine, pass through the shared_ptr on the stack, keep hold of the coroutine but exit the original scope, any shared_ptr you unpack from the stack inside the coroutine later is going to point to dead memory as it never got a chance to add a count to the shared_ptr object
  2. If you don't go out of the original scope but call the coroutine through to completion from within that scope, you might expect that the shared_ptr object still exists in the original scope, but actually it won't, because when you pulled it off the stack inside the coroutine it didn't add an extra ref count to the object, so when the coroutine ends, the shared_ptr essentially believes it is holding the final pointer to the shared object, and deletes it.

from minicoro.

Related Issues (14)

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.