0

我对用户定义线程的上下文内容很陌生。我在上下文上写了一个简单的程序......但它给了我分割错误......

#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 

新的而不是malloc??有任何想法吗??

4

1 回答 1

1

你忘记了:

a.uc_stack.ss_size=32767;
于 2012-08-24T08:10:19.517 回答