Boost logo

Boost Users :

Subject: [Boost-users] [coroutine] Is there a max number of coroutines that can be created?
From: José (josessantos_at_[hidden])
Date: 2014-07-10 16:57:26


Dear all,

I am creating a "lot" of coroutines in my code. When I create more than 32744 coroutines (for this example) the program ends with segmentation fault.

So, I would like to known if there is a limit number for active coroutines?

Code below reproduces this situation:

#include<iostream>
#include<cstdlib>
#include<boost/coroutine/all.hpp>
#include <boost/bind.hpp>
#include <vector>

class MyClass{
    public:
        boost::coroutines::coroutine<void>::pull_type* startResume;
        MyClass() {
            startResume = NULL;
        }
        void resume(){
            if(startResume && *(startResume))
                (*(startResume))();
        }
        void doSomething ( boost::coroutines::coroutine< void >::push_type & gbck){

            gbck();

            return;
        }
};

int main(int argc, char** argv){
    int max = 10;
    if (argc > 1)
        max = atoi(argv[1]);

    std::vector<MyClass*> myobjects(max);
    for(int xx=0; xx < max; xx++){
        myobjects[xx] = new MyClass ();
        myobjects[xx]->startResume = new boost::coroutines::coroutine<void>::pull_type( boost::bind(&MyClass::doSomething, myobjects[xx], _1)  );
    }

    for(int xx=0; xx < max; xx++)
        myobjects[xx]->resume();
}


Thanks in advance for your help,
Jose

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net