Linux中国论坛's Archiver

cbl20020825 发表于 2007-11-23 11:30

一个最简单的线程程序,居然出现段错误,请大家帮忙看看啊!

我刚接触线程和进程的设计,我写了一个很简单的程序,就只生成一个线程让它同步进程而运行,代码如下:
#include <pthread.h>
#include <stdlib.h>
void *test(void * arg)
{
printf("the arg is %d",*((int *)arg));
return NULL;
}
int main()
{
pthread_t * p;
int ii=100;
pthread_create(p,NULL,test,(void *)&ii);
printf("Parent");
exit(0);
}
我编译:gcc -lpthread main.c
执行:./a.out
就出现了段错误,我跟踪代码执行,发现是在线程函数test里面出现问题,当退出test时就提示段错误了,请大家帮忙看看啊!

上海租车网 发表于 2008-4-16 15:27

不顶,就这样

[img]http://pic7.soso.com/pic?fid=12252229829834496967[/img]
[url=http://www.dreamathk.com][b]注册香港公司[/b][/url]网 [url=http://www.54admin.org]交换友情链接[/url]

yaj114777175 发表于 2008-4-21 01:12

线程没出息退出!!

线程没出息退出!!

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.