Comments (2)
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.
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:
- 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
- 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)
- Mild red zone bug. HOT 2
- Usage of "fiber_storage" in the Win32 implementation HOT 2
- Release temporary variables on the stack HOT 1
- Optimize per coroutine memory footprint with virtual memory mapping HOT 1
- Pages with no access to catch stack overflows? HOT 2
- C++ exceptions question HOT 2
- C++ Exceptions Revisited HOT 4
- Documentation of saved state and compatible instruction extensions HOT 2
- Makefile mt-example link fails due to -lpthread order wrong HOT 1
- stack overflow with VS2008 / VS2019 HOT 2
- Can this run in Switch? HOT 2
- Symmetric coroutines? HOT 2
- Interrupting a long-running coroutine and moving it to another os-level thread HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minicoro.