Board logo

标题: ARM_Linux多线程编程示例 [打印本页]

作者: samwalton    时间: 2013-9-7 14:29     标题: ARM_Linux多线程编程示例

 #include <pthread.h> #include"reader.h"
  void *create(void *arg)
  { while(1)
  { printf("thread is Running …… ");sleep(5);}
  }
  void *ReaderThread(void *arg)
  { int reader_fd;char buf[32];
  if((reader_fd=OpenReader("/dev/tty0"))==-1)
  { puts("Open Dev Error!\r\n");}
  while(1)
  { if(ReadId(reader_fd,buf,32)==1)
  { printf("Read ID=%s\r\n",buf);}
  CloseReader(reader_fd);
  }
  int main(int argc, char *argv[])
  {
  pthread_t tidp;int rc1,rc2;
  rc1=pthread_create(&tidp,NULL,create,NULL);if(rc1!=0)
  { printf("pthread_create is not created …… \r\n");return -1;}
  printf("prthread_create is created…… \r\n");
  rc2=pthread_create(&tidp,NULL,ReaderThread,NULL);if(rc2!=0)
  { printf("ReaderThread is not created …… \r\n");return -1;}
  printf("ReaderThread is created…… \r\n");
  while(1)
  { printf("System is Runing……\r\n");sleep(1);}
  return 0;}




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0