Hi all,
I am writting a code with Coroutines lib, this code uses coroutines in a recursive way but when I create a large number of coroutines the program crashes (segmentation fault). I write a simplified version that reproduces this error:
#include<iostream>
#include<cstdlib>
#include
#include
#include
class FClass{
private:
int n;
public:
boost::coroutines::coroutine<void>::pull_type* startResume;
FClass(int n) : n(n){
startResume = NULL;
}
void resume(){
if(startResume && *(startResume))
(*(startResume))();
}
void doSomething ( boost::coroutines::coroutine< void >::push_type & fPause){
if (n > 2){
FClass* tc1 = new FClass(--n);
tc1->startResume = new boost::coroutines::coroutine<void>::pull_type( boost::bind( &FClass::doSomething, tc1, _1) );
FClass* tc2 = new FClass(--n);
tc2->startResume = new boost::coroutines::coroutine<void>::pull_type( boost::bind( &FClass::doSomething, tc2, _1) );
fPause();
tc1->resume();
tc2->resume();
}
return;
}
};
int main(int argc, char** argv){
int max = 10;
if (argc > 1){
max = atoi(argv[1]);
}
FClass* firstObject = new FClass (max) ;
firstObject->startResume = new boost::coroutines::coroutine<void>::pull_type( boost::bind(&FClass::doSomething, firstObject, _1) );
firstObject->resume();
}
gdb output reports:"memset () at ../sysdeps/x86_64/memset.S:78 ../sysdeps/x86_64/memset.S:No such file or directory."
Anybody can help me?
Regards,
Van