#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
pthread_mutex_t mutex;
char buf='A';
int i = 0;
void *ptd(void *arg)
{
int j=30;
while(j--)
{
pthread_mutex_lock(&mutex);
printf("%c",buf+(i++%3));
fflush(stdout);
pthread_mutex_unlock(&mutex);
}
}
int main(int argc,char *argv[])
{
pthread_t tid[3]={0};
int ted[3]={1,2,3};
void *rev;
pthread_create(&tid[0],NULL,ptd,&ted[0]);
pthread_create(&tid[1],NULL,ptd,&ted[1]);
pthread_create(&tid[2],NULL,ptd,&ted[2]);
sleep(1);
pthread_join(tid[0],NULL);
pthread_join(tid[1],NULL);
pthread_join(tid[2],NULL);
//退出主线程
pthread_exit(NULL);
//释放互斥量
pthread_mutex_destroy(&mutex);
}