当前位置: 技术问答>linux和unix
线程函数没有运行?
来源: 互联网 发布时间:2017-02-16
本文导语: 代码如下: #include #include #include #include #include void *mypthead(void *arg) { pthread_t pid; pid=pthread_self(); printf("pthread's id is %lun",pid); printf("pthread ranningnr"); pthread_exit(NULL); } int mai...
代码如下:
#include
#include
#include
#include
#include
void *mypthead(void *arg)
{
pthread_t pid;
pid=pthread_self();
printf("pthread's id is %lun",pid);
printf("pthread ranningnr");
pthread_exit(NULL);
}
int main()
{
pthread_t mythread;
int ret;
ret=pthread_create(&mythread,NULL,mypthead,NULL);
if(ret!=0)
{
printf("can't ran: %sn",strerror(errno));
exit(-1);
}
return 0;
}
编译:
gcc selfPthread.c -o pthread -lpthread
运行:
$ ./pthread
运行后终端无输出,请问是什么问题?谢谢~
#include
#include
#include
#include
#include
void *mypthead(void *arg)
{
pthread_t pid;
pid=pthread_self();
printf("pthread's id is %lun",pid);
printf("pthread ranningnr");
pthread_exit(NULL);
}
int main()
{
pthread_t mythread;
int ret;
ret=pthread_create(&mythread,NULL,mypthead,NULL);
if(ret!=0)
{
printf("can't ran: %sn",strerror(errno));
exit(-1);
}
return 0;
}
编译:
gcc selfPthread.c -o pthread -lpthread
运行:
$ ./pthread
运行后终端无输出,请问是什么问题?谢谢~
|
编译运行,一切正常。
[zcm@t #10]$ls
a.c csdn.sql makefile socket
[zcm@t #11]$make
gcc -g -o a a.c -lpthread
[zcm@t #12]$./a
pthread's id is 3077655408
pthread ranning
[zcm@t #13]$
[zcm@t #10]$ls
a.c csdn.sql makefile socket
[zcm@t #11]$make
gcc -g -o a a.c -lpthread
[zcm@t #12]$./a
pthread's id is 3077655408
pthread ranning
[zcm@t #13]$