linux OS 多线程学习

/***********************
* author :lzhenf
* it's a program with args for mutithread in linux OS
* date:2012.3.27
* **********************
*/
#include <stdio.h>
#include <pthread.h>

void* mythread(void* args)
{
char *str1;
str1 = (char *)args;
sleep(5);
printf("the thread id is %u",(unsigned int )pthread_self());
printf("the thread id num is %d",getpid());
printf("create parameter is %s\n",str1);
return (void*)0;
}

int main(int argc ,char *argv[])
{
pthread_t id;
int error;

char a[]="lzhenf";
char *p = a;

error = pthread_create(&id , NULL , (void*)mythread,(void*)p);

if (error)
{
printf("the create is error\n");
return -1;
}
sleep(1);
printf("pthread_create is created \n");
pthread_join(id,NULL);

return 0;
}
原文地址:https://www.cnblogs.com/lzhenf/p/2419658.html