- 论坛徽章:
- 0
|
本帖最后由 new_new_one 于 2010-09-14 18:12 编辑
小弟刚学多线程编程。写了这样一段代码- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <pthread.h>
- void* threadnew(void)
- {
- printf("this is %u thread\n",(int)pthread_self());
- pthread_exit(0);
- }
- int main()
- {
- pthread_t pthr1,pthr2;
- if(pthread_create(&pthr1,NULL,(void*)threadnew,NULL)){
- fprintf(stderr, "error create 1\n");
- exit(1);
- }
- if(pthread_create(&pthr2,NULL,(void*)threadnew,NULL)){
- fprintf(stderr, "error create 2\n");
- exit(1);
- }
- //pthread_join(pthr1,NULL);
- //printf("111111\n");
- //pthread_join(pthr2,NULL);
- //printf("222222\n");
- sleep(3);
- return 0;
- }
复制代码 编译执行:
[root@localhost test005]# gcc -lpthread test.c -g
[root@localhost test005]# ./a.out
this is 3086392208 thread
Segmentation fault
[root@localhost test005]#
怎么会出这样的问题,轻大家帮忙看看.
即时我把代码中的那些注释行加上去也是出现:Segmentation fault |
|