Академический Документы
Профессиональный Документы
Культура Документы
h>
#include <pthread.h>
#include <semaphore.h>
#include <string.h>
sem_t eco_wait;
sem_t busi_wait;
sem_t eco_canc;
sem_t busi_canc;
struct plane
{
int avail;
int seat;
char pname[50];
} economic[10],business[6];
int flag=0;
int i;
sem_wait(&eco_wait);
printf("Welcome %s\n",p);
for(i=0; i<10; i++)
{
if(economic[i].avail==0)
{
flag=1;
break;
}
}
if(flag==0)
{ sleep(4);
printf("Sorry Sir, we are fully occupied for
now\n_____________________________________________\n");
sem_post(&eco_wait);
return ;
}
economic[i].avail=1;
strcpy(economic[i].pname,p);
economic[i].seat=i;
printf("Thank You for booking your flight with INDIAN Airlines\n");
printf("Following are your Booking Details\n");
printf("Name: %s",economic[i].pname);
printf("\nSeat No. %d\n",i);
printf("Class:
Economic\n_________________________________________________________________________
_\n");
sleep(4);
sem_post(&eco_wait);
}
int main()
{
pthread_t tid[20],tcan[5];
sem_init(&eco_wait,0,1);
sem_init(&busi_wait,0,1);
sem_init(&eco_canc,0,1);
sem_init(&busi_canc,0,1);
//printf("Hello WOlrd\n");
char pnames[20][50]= {
"Elenore Paredes",
"Dionne Pleasants",
"Erna Woerner",
"Karri Sloat",
"Luann Dipasquale",
"Jenette Toler",
"Louis Rossetti",
"Inell Keehn",
"Amberly Samayoa",
"Dudley Naumann",
"Branden Rust",
"Leonel Holsey",
"Trinity Hodes",
"Deb Fossum",
"Dovie Starkey",
"Hilaria Cano",
"Regan Burnham",
"Kenny Maria",
"Jane Skeens",
"Roxy Stephan"
};
int i;
for(i=0; i<12; i++)
{
pthread_create(&tid[i],NULL,book_eco,(void *)pnames[i]);
//pthread_join(tid[i],NULL);
}
for(i=0; i<12; i++)
{
pthread_join(tid[i],NULL);
}
for(i=12; i<=19; i++)
{
pthread_create(&tid[i],NULL,book_busi,(void *)pnames[i]);
//pthread_join(tid[i],NULL);
}
for(i=12; i<=19; i++)
{
pthread_join(tid[i],NULL);
}
//pthread_create(&tcan[0],NULL,cancel_booking_busi,(void *)pnames[12]);
pthread_create(&tcan[1],NULL,cancel_booking_eco,(void *)pnames[5]);
pthread_create(&tcan[2],NULL,cancel_booking_eco,(void *)pnames[4]);
//pthread_join(tcan[0],NULL);
pthread_join(tcan[1],NULL);
pthread_join(tcan[2],NULL);
}