在linux中获取SIGSEGV的上下文

时间:2012-08-24 08:00:49

标签: c++ linux multithreading scope

我是用户定义线程的上下文新手。我在上下文中写了一个简单的程序......但是它给了我分段错误......

#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 ??任何想法??

1 个答案:

答案 0 :(得分:1)

你忘记了:

a.uc_stack.ss_size=32767;