#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>struct student{
char *s ;
char *s1;
int age;
};
void * thr_fun(void *stu)
{
sleep(1);
printf
("frist is %s,second is %s , thrid is %d\n",( (struct student*)stu )->s,( (struct student *)stu )->s1 ,( (struct student*)stu )->age);
return(void *)0;}int main (int argc,char *argv[])
{ int err;
int i;
int *rval;
pthread_t nid;
struct student stu;
stu.s1="new thread ";
stu.s="main thread ";
stu.age = 20;
err = pthread_create(&nid,NULL,thr_fun,(void *)(&stu));
if(err != 0){
printf("new thread creat fail\n");
return -1;
}
for(i=0 ;i<argc ;i++){
printf("main thread args is %s\n",argv[i]);
}
// sleep(1);
pthread_exit(rval);// problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// return 0;
}
当调用pthread_exit()函数 代替sleep()函数时 并且把 结构体里 char s[20]; char s1[20]; 用char *s ,*s1字符串指针代替时
总有s1 会变成 NULL .
拜托 大家看看 说说 谢谢!
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>struct student{
char *s ;
char *s1;
int age;
};
void * thr_fun(void *stu)
{
sleep(1);
printf
("frist is %s,second is %s , thrid is %d\n",( (struct student*)stu )->s,( (struct student *)stu )->s1 ,( (struct student*)stu )->age);
return(void *)0;}int main (int argc,char *argv[])
{ int err;
int i;
int *rval;
pthread_t nid;
struct student stu;
stu.s1="new thread ";
stu.s="main thread ";
stu.age = 20;
err = pthread_create(&nid,NULL,thr_fun,(void *)(&stu));
if(err != 0){
printf("new thread creat fail\n");
return -1;
}
for(i=0 ;i<argc ;i++){
printf("main thread args is %s\n",argv[i]);
}
// sleep(1);
pthread_exit(rval);// problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// return 0;
}
当调用pthread_exit()函数 代替sleep()函数时 并且把 结构体里 char s[20]; char s1[20]; 用char *s ,*s1字符串指针代替时
总有s1 会变成 NULL .
拜托 大家看看 说说 谢谢!
解决方案 »
- linux 多线程通讯及同步问题
- 求助!!!Ubuntu安装busybox编译失败,求大神帮忙看看
- 请教各位大神,如何实现:多台linux服务器,可以使用一个用户登陆,且在其中一台服务器中修改用户密码,其他服务器也同步修改了。
- suse 如何安装例如libssl-dev 之类一般用 apt-get安装的软件?
- sshd 服务与 /etc/security/limits.conf 的关系
- 升级SSH版本以后无法登录
- 如何在Ubuntu下用c++调用vlfeat中的sift
- shell expect settimeout超时问题
- vmware虚拟机上linux系统配置ip都正确,却无法访问网关
- 下面如何简单用命令替换,不需要vi进去修改
- 关于USB HID 中键盘发送数据,最后怎么让键盘弹起
- Linux书籍推荐
pthread_t nid;
int pad[32] = { };