首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

线程函数没有运行?该怎么处理

2012-04-19 
线程函数没有运行?代码如下:#includepthread.h#includestdlib.h#includestdio.h#includestring.h#

线程函数没有运行?
代码如下:
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<errno.h>
void *mypthead(void *arg)
{
  pthread_t pid;
   
  pid=pthread_self();
  printf("pthread's id is %lu\n",pid);
  printf("pthread ranning\n\r");
   
  pthread_exit(NULL);
}

int main()
{
  pthread_t mythread;
  int ret;
   
  ret=pthread_create(&mythread,NULL,mypthead,NULL);
  if(ret!=0)
  {
  printf("can't ran: %s\n",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]$

热点排行