线程的基本概念

来源:互联网 发布:软件开发职业培训 编辑:程序博客网 时间:2024/04/30 13:07

#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void print_msg(char *ptr);

int main()
{
 pthread_t thread1, thread2;
 int i,j; 
 char *msg1="Hello/n";
 char *msg2="World/n";
 pthread_create(&thread1,NULL, (void *)(&print_msg), (void *)msg1);
 pthread_create(&thread2,NULL, (void *)(&print_msg), (void *)msg2);
 sleep(1);
 return 0;
}

void  print_msg(char *ptr)
{
 int retval; 
 int id=pthread_self();
 printf("Thread ID: %lx/n",id); 
   printf("%s",ptr);
 pthread_exit(&retval);
}

原创粉丝点击