#include <stdio.h>
#include <pthread.h>
#define SIZEOFTHREAD 4
#define THREADNUM 3
pthread_t thread[THREADNUM];
void *thread1(int tn)
{
while(1)
{
printf ("thread : I'm thread %d/n", tn);
sleep(2);
}
}
void thread_create(void)
{
int i;
for ( i = 0; i < THREADNUM; i ++)
{
memset( &thread[i], 0, SIZEOFTHREAD);
printf("turn to i:%d/n", i);
pthread_create( &thread[i], NULL, thread1, i );
sleep(3);
}
}
void thread_wait(void)
{
pthread_join(thread[0],NULL); //线程挂起
}
int main()
{
thread_create();
thread_wait();
return 0;
}