#include "stdio.h"
#include "unistd.h"
#include "pthread.h"
void *func(void *p)
{
*(int*)p=200;
int i;
for (i=0; i<20; i++)
{
write(1, ".", 1);
sleep(1);
}
return (void*)9999;
}
int main()
{
pthread_t id;
int x = 100;
pthread_create(&id, NULL, func, &x);
int i;
for (i=0; i<10; i++)
{
write(1, "*", 1);
sleep(1);
}
printf("x=%d\n", x);
void *v;
puts("Wait for thread over");
pthread_join(id, &v);
printf("The thread returned %d\n", (int)v);
return 0;
}
多线程实例
原文:http://www.cnblogs.com/zhangwuliang/p/4193930.html