/* ------ main2.c: simple simulation ------ */ #include #include #include double ARRIVAL_DELAY; double SERVICE_DELAY; PCBType *Server; /* The server thread */ PCBType *Generator; /* The thread that create client threads */ /* ------------------------------------------------------- Client() ------------------------------------------------------- */ void ClientProc() { printf("Now = %lf: Client arrives\n", GetSimTime()); Enqueue(TAIL, Server, 0, 0, 0); ReActivate(Server, 0, 0); Passivate(0, 0); printf("Now = %lf: Client is done... my delay = %lf\n", GetSimTime(), GetSimTime() - GetMyArrivalTime() ); Terminate(); } /* ------------------------------------------------------- Client generator process ------------------------------------------------------- */ void GeneratorProc() { printf("Generator has started.\n"); while(1) { Hold( ARRIVAL_DELAY ); Generate("Cli", ClientProc, 0); } } /* ------------------------------------------------------- Server() ------------------------------------------------------- */ void ServerProc() { PCBType *Client; while (1) { if (MyQLength() == 0) { Passivate(0, 0); } Dequeue(HEAD, &Client, NULL, NULL, NULL); Hold( SERVICE_DELAY ); ReActivate(Client, 0, 0); } } int main(int argc, char **argv) { double SimLength; printf("Length of simulation run = "); scanf("%lf", &SimLength); printf("Arrival delay = "); scanf("%lf", &ARRIVAL_DELAY); printf("Service delay = "); scanf("%lf", &SERVICE_DELAY); printf("Init Prosim\n"); InitProsim(1000, 1000, 1000); printf("Create generator\n"); Generator = Generate("Gen", GeneratorProc, 0); printf("Create server\n"); Server = Generate("Serv", ServerProc, 0); printf("Start simulation....\n"); StartSimulate(SimLength); printf("Done.\n"); }