lzhenf

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
/***********************
* 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;
}
posted on 2012-03-27 15:47  lzhenf  阅读(188)  评论(0编辑  收藏  举报