I am new to this context stuff of the user defined threads. I wrote a simple program on the contexts… but its giving me segmentation error…
#include<iostream>
#include<ucontext.h>
#include<stdlib.h>
using namespace std;
void fun1()
{
cout<<"from 1";
}
void fun2()
{
cout<<"from 2";
}
int main()
{
ucontext_t a,b;
cout<<"y";
getcontext(&b);
b.uc_link=0;
b.uc_stack.ss_sp=malloc(32767);
b.uc_stack.ss_size=32767;
b.uc_stack.ss_flags=0;
makecontext(&b, fun1, 0);
getcontext(&a);
a.uc_link=&b;
a.uc_stack.ss_sp=malloc(32767);
a.uc_stack.ss_flags=0;
makecontext(&a, fun2, 0);
setcontext(&a);
return 0;
}
`
I want to know how to allocate memory using
new
rather than malloc?? any ideas??
You have forgotten: