#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
int ticket = 30;
void *thread1(void)
{
while(1)
{
if(ticket > 0)
{
printf("A");
ticket--;
sleep(1);
}
else
{
break;
}
}
return NULL;
}
void *thread2(void)
{
while(1)
{
if(ticket > 0)
{
printf("B");
ticket--;
sleep(1);
}
else
{
break;
}
}
return NULL;
}
void *thread3(void)
{
while(1)
{
if(ticket > 0)
{
printf("C");
ticket--;
sleep(1);
}
else
{
break;
}
}
return NULL;
}
int main()
{
int i=0, ret=0;
pthread_t id1,id2,id3;
ret = pthread_create(&id1, NULL, (void*)thread1, NULL);
ret = pthread_create(&id2, NULL, (void*)thread2, NULL);
ret = pthread_create(&id3, NULL, (void*)thread3, NULL);
pthread_join(id1, NULL);
pthread_join(id2, NULL);
pthread_join(id3, NULL);
return 0;
}