Segfault occurs on initialization in pthread only

I cannot understand why the following pseudo code is causing a segfault. Using pthreads to run a function I run into a SEGFAULT initializing an integer to zero. When `my_threaded_function` not in threaded context or if I called function from the main thread there is no issue. The SEGFAULT doesn't occur on initializing `rc=0;`bu only inside the `maze_init` function. I have confirmed that I am out of stack space. But I can't think of what is causing the function to behave differently inside the pthread (no shared memory involved), the address `&aa` cannot be accessed according to gdb. Why would a stack variable's address not be on the stack? int maze_init(Maze*m, char* filename) { FILE *fp; int aa, bb, rc; aa = 0; /// SEGFAULT HERE ... return 1; } void* my_threaded_function(void* arg) { Maze maze; int rc; rc = 0; rc = maze_init(&maze,"test.txt"); return rc; pthread_exit((void*)1); } int main(int argc,char** argv){ pthread_t t; pthread_create(&t, NULL, my_threaded_function,(void*)0); sleep(10); } - edit (fixed code typo to `return rc`)

以上就是Segfault occurs on initialization in pthread only的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准