コード例 #1
0
ファイル: halt2.c プロジェクト: shadowwalk/OSNachos
int main() {
	
	int rv = 0, index = 0, cvrv = 0;
	int mvVal = 0;
	
	Print_Stmt("Calling start simulation\n");
	StartSimulation();
	Print_Stmt("In halt.c\n");
	
	
	rv = CreateLock("firstLock", 9, 1);
	
	
    rv = CreateLock("secondLock", 10, 1); 
	rv = CreateLock("firstLock", 9, 2); 
 	rv = CreateLock("secondLock", 10, 2);
	rv = CreateLock("firstLock", 9, 3); 
 	rv = CreateLock("secondLock", 10, 3);
	rv = CreateLock("firstLock", 9, 4); 
 	rv = CreateLock("secondLock", 10, 4);
	rv = CreateLock("firstLock", 9, 5); 
 	rv = CreateLock("secondLock", 10, 5);
	rv = CreateLock("firstLock", 9, 6); 
 	rv = CreateLock("secondLock", 10, 6);
	rv = CreateLock("firstLock", 9, 7); 
 	rv = CreateLock("secondLock", 10, 7);
	rv = CreateLock("firstLock", 9, 8); 
 	rv = CreateLock("secondLock", 10, 8);
	rv = CreateLock("firstLock", 9, 9); 
 	rv = CreateLock("secondLock", 10, 9);
	rv = CreateLock("firstLock", 9, 10); 
 	rv = CreateLock("secondLock", 10, 10);
	
	
	Acquire(rv);
 	Release(rv); 
	
	cvrv = CreateCV("firstCV", 7, 0);
 	cvrv = CreateCV("firstCV", 7, 0);
	cvrv = CreateCV("firstCV2", 8, 0);
	cvrv = CreateCV("firstCV3", 8, 0); 
	
 	Wait(cvrv, rv); 
	Signal(cvrv, rv); 
	
	DestroyLock(rv); 
	
	rv = CreateCV("firstCV", 7, 4);  
	CreateMV("firstMV", 7, 0); 
	
 	rv = CreateMV("firstMV", 7, 0);
	SetMV(rv, 3);
	mvVal = GetMV(rv);
	
	Print_1Arg("MV value obtained in halt is %d\n", mvVal); 
	
	Print_Stmt("Exiting in halt.c\n");
	
}
コード例 #2
0
int main()
{
	mv = CreateMV("mv1");
	mv2 = CreateMV("mv2");
	
	lck = CreateLock("lock1");
	lck2 = CreateLock("lock2");
	
	cv = CreateCV("cv1");

	for (loop =0; loop<500; loop++) 
	{
		AcquireLock(lck);
		SignalCV(lck,cv);

		AcquireLock(lck2);
		ret = GetMV(mv2);
		ReleaseLock(lck2);
		
		if (ret != 21)/*This will wait only if the other one isnt finished*/
			WaitCV(lck,cv);

		mvEdit = GetMV(mv);
		Print("Client 2: Monitor variable was read to be %d..",mvEdit,-1,-1);

		mvEdit+=7;
	
		
		ret=SetMV(mv,mvEdit);
		mvEdit = GetMV(lck);
	
		Print("Client 2: Monitor variable was set to be %d..",mvEdit,-1,-1);
		
		ReleaseLock(lck);	

		Print("Client 2: %d Iterations done..",loop,-1,-1);
	}
	
	AcquireLock(lck2);
	ret = SetMV(mv2,21);
	
	/*this monitor variable is set to 21 here to signify 
	*one of the processes is over and the other will not
	*wait for it to signal it
	*/
	ReleaseLock(lck2);
	
	AcquireLock(lck);
	SignalCV(lck,cv);
	ReleaseLock(lck);

}
コード例 #3
0
int
main()
{
	int lock3,mv3,cv3;

	lock3 = CreateLock("lock3",5);
	cv3 = CreateCV("cv3",3);
	mv3 = CreateMV("mv3",3,5);

	WriteToConsole("\nAcquiring lock3 in rpcclient5\n\0", -1, -1, -1);
	if((Acquire("lock3",5)) == -1){
		WriteToConsole("Error acquiring lock3 in rpcclient5\n\0",-1,-1,-1);
		Exit(0);
	}

	if((Wait("cv3",3, "lock3",5)) == -1){
			WriteToConsole("Error waiting on cv3 and lock3 in rpcClient1\n\0",-1,-1,-1);
			Exit(0);
	}

	WriteToConsole("\nGot Signal on cv3 lock3 from rpcClient1\n\0", -1, -1, -1);
	WriteToConsole("\nValue of mv3 index 3 set by rpcClient1 is %d\n\0", GetMV("mv3",3,3), -1, -1);
	Release("lock3",5);

	DeleteLock("lock3",5);
	WriteToConsole(" Deleted Lock3\n\0",-1,-1,-1);
	DeleteMV("mv3",3);
	WriteToConsole(" Deleted MV3\n\0",-1,-1,-1);
	DeleteCV("cv3",3);
	WriteToConsole(" Deleted CV3\n\0",-1,-1,-1);

	Exit(0);
}
コード例 #4
0
int main()
{
	int lockId, lockStatus,locktemp,mv;
	
	WriteToConsole("\nUser Program 4\n",-1,-1,-1);
	
	WriteToConsole("\nCreating Monitor Variable - mv1\n",-1,-1,-1);
	mv = CreateMV("mv1",3,0);
	
	WriteToConsole("\nCreating Lock - lock2\n",-1,-1,-1);
	if((locktemp = CreateLock("lock2",5)) == -1){
		WriteToConsole("Error Creating lock2 in User Program 4\n\0",-1,-1,-1);
		Exit(0);
	}
	
	WriteToConsole("\nAcquiring lock2\n", -1, -1, -1);
	if((Acquire("lock2",5)) == -1){
		WriteToConsole("Error acquiring lock2 in User Program 4\n\0",-1,-1,-1);
		Exit(0);
	}
	
	WriteToConsole("\nReleasing Lock lock2\n",-1,-1,-1);
	Release("lock2",5);
	
	WriteToConsole("\nUser Program 4 Exiting\n",-1,-1,-1);
   Exit(0);
}
コード例 #5
0
int
main()
{
	int lock2, cv2, mv2;

	if((lock2 = CreateLock("lock2",5)) == -1){
		WriteToConsole("Error Creating lock2 in rpcClient4\n\0",-1,-1,-1);
		Exit(0);
	}
	WriteToConsole("lock2 created in rpcClient4 with lockid: %d\n\0",lock2,-1,-1);
	
	WriteToConsole("cv1 created in rpcClient4 with CVid: %d\n\0",cv2,-1,-1);
	if((cv2 = CreateCV("cv2", 3)) == -1){
		WriteToConsole("Error Creating CV2 in rpcClient4\n\0",-1,-1,-1);
		Exit(0);
	}
	WriteToConsole("cv2 created in rpcClient4 with CVid: %d\n\0",cv2,-1,-1);
	
	if((mv2 = CreateMV("mv2", 3, 5)) == -1){
		WriteToConsole("Error Creating MV2 in rpcClient2\n\0",-1,-1,-1);
		Exit(0);
	}
	WriteToConsole("mv2 created in rpcClient2 with MVid: %d\n\0",mv2,-1,-1);
	
	if((Acquire(lock2)) == -1){
		WriteToConsole("Error acquiring lock2 with id:%d in rpcClient4\n\0",lock2,-1,-1);
		Exit(0);
	}
	WriteToConsole("\nAcquired lock2: %d\n\0", lock2, -1, -1);
	WriteToConsole("\nValue of MV2 index 0 set by rpcClient4 is %d\n\0", GetMV(mv2,0), -1, -1);
	
	if((SetMV(mv2, 1, 5)) == -1){
		WriteToConsole("Error setting mv2 in rpcClient4\n\0",-1,-1,-1);
		Exit(0);
	}
	WriteToConsole("\nMV2 index: 1 set to 5 by rpcClient4\n\0", -1, -1, -1);
	
	WriteToConsole("\nSignalling on CV2 Lock2 to rpcClient1\n\0", -1, -1, -1);
	if((Signal(cv2, lock2)) == -1){
		WriteToConsole("Error signalling on cv2 and lock2 in rpcClient4\n\0",-1,-1,-1);
		Exit(0);
	}
	if((Release(lock2)) == -1){
		WriteToConsole("Error releasing lock2 with id:%d in rpcClient1\n\0",lock2,-1,-1);
		Exit(0);
	}
	WriteToConsole("\nReleased lock2: %d\n\0", lock2, -1, -1);

	DeleteLock(lock2);
	WriteToConsole("Sent DeletLock Request id: %d\n\0",lock2,-1,-1);
	DeleteCV(cv2);
	WriteToConsole("Sent DeletCV Request id: %d\n\0",cv2,-1,-1);
	DeleteMV(mv2);
	WriteToConsole("Sent DeleteMV Request id: %d\n\0",mv2,-1,-1);
	Exit(0);
}
コード例 #6
0
void main()
{

        
		CreateLock("lock1");
        Print("\nLock by name 'lock1' Created.\n",1,1,1);
		CreateLock("lock2");
        Print("\nLock by name 'lock2' Created.\n",1,1,1);
        CreateCV("cv1");	
        Print("\nCV by name 'cv1' Created.\n",1,1,1);
        CreateCV("cv2");	
        Print("\nCV by name 'cv2' Created.\n",1,1,1);
        CreateMV("mv1",5);
        Print("\nMV by name 'mv1' Created.\n",1,1,1);        
		CreateMV("mv2",4);
        Print("\nMV by name 'mv1' Created.\n",1,1,1);

		Exit(0);
}
コード例 #7
0
ファイル: test2_c2.c プロジェクト: shengzhc/CSCi402
void main()
{
    Print("\nTest2 is for waiting and signaling condition variable.\n", sizeof("\nTest2 is for waiting and signaling condition variable.\n")/sizeof(char), 0, 0);
     l1 = CreateLock("l1", 2);
     c1 = CreateCondition("c1", 2);
     m1 = CreateMV("m1", 2, 3);
    
    AcquireLock(l1);
    Print("client2 of Test2 has acquired lock1.\n", sizeof("client2 of Test2 has acquired lock1.\n")/sizeof(char), 0, 0);
    SetMV(m1, 1, 10);
    SignalCondition(c1, l1);
    Print("client2 of Test2 signals client1.\n", sizeof("client2 of Test2 signals client1.\n")/sizeof(char), 0, 0);
    ReleaseLock(l1);
    Print("client2 of Test2 has released lock1.\n", sizeof("client2 of Test2 has released lock1.\n")/sizeof(char), 0, 0);
    Exit(0);
}
コード例 #8
0
ファイル: test3_c2.c プロジェクト: shengzhc/CSCi402
void main()
{
    Print("\nTest3 is for waiting and broadcasting condition variable.\n", sizeof("\nTest3 is for waiting and broadcasting condition variable.\n")/sizeof(char), 0, 0);
     l1 = CreateLock("l1", 2);
     c1 = CreateCondition("c1", 2);
     m1 = CreateMV("m1", 2, 3);
        
    AcquireLock(l1);
    Print("client2 of Test3 has acquired lock1.\n", sizeof("client2 of Test3 has acquired lock1.\n")/sizeof(char), 0, 0);
    if (value == 0) {
        Print("client2 is waiting other to signal.\n", sizeof("client2 is waiting other to signal.\n")/sizeof(char), 0, 0);
        WaitCondition(c1, l1);
    }
    value = GetMV(m1, 1);
    Print("The MV value of client2 is [%d].\n", sizeof("The MV value of client2 is [%d].\n")/sizeof(char), 1, value);
    ReleaseLock(l1);
    Print("client2 of Test3 has released lock1.\n", sizeof("client2 of Test3 has released lock1.\n")/sizeof(char), 0, 0);
    Exit(0);
}
コード例 #9
0
int main()
{
	Trace("Creating Lock", 0x9999);
	Trace("\n", 0x9999);
	lock = ServerCreateLock("Lock", sizeof("Lock"), 1);
	Trace("Lock's index: ", lock);
	Trace("\n", 0x9999);
	
	Trace("Creating CV", 0x9999);
	Trace("\n", 0x9999);
	cv = ServerCreateCV("CV", sizeof("CV"), 1);
	Trace("CV's index: ", cv);
	Trace("\n", 0x9999);
	
	Trace("Creating MV\n", 0x9999);
	mv = CreateMV("MV", sizeof("MV"), 1, 10);
	Trace("MV's index: ", mv);
	Trace("\n", 0x9999);
	Trace("MV's value: ", GetMV(mv, 0));
	Trace("\n", 0x9999);
	
	Trace("Acquiring lock\n", 0x9999);
	ServerAcquire(lock, 0);
	
	Trace("Incrementing MV\n", 0x9999);
	SetMV(mv, 0, GetMV(mv, 0)+1);
	
	Trace("Waiting on CV with Lock\n", 0x9999);
	ServerWait(cv, 0, lock, 0);
	Trace("Woken up from wait\n", 0x9999);
	Trace("Now deleteing lock and cv\n", 0x9999);
	ServerRelease(lock, 0);
	
	ServerDestroyLock(lock, 0);
	ServerDestroyCV(cv, 0);
	
	Trace("Final MV value should be 4\n", 0x9999);
	Trace("Final MV value: ", GetMV(mv, 0));
	Trace("\n", 0x9999);
	/* not reached */
	Exit(0);
}
コード例 #10
0
int main()
{
	mv = CreateMV("mv1");
	lck = CreateLock("lock1");

	AcquireLock("lock1");
	mv2 = GetMV("mv1");
	Print("Client 2: Monitor variable was read to be %d..",mv2,-1,-1);
	ReleaseLock("lock1");

	mv2++;
	AcquireLock("lock1");
	ret=SetMV("mv1",mv2);
	mv2 = GetMV("mv1");
	
	Print("Client 2: Monitor variable was set to be %d..",mv2,-1,-1);
	ReleaseLock("lock1");

	Exit(0);

}
コード例 #11
0
int main () {

  int lock0 = -1;
  int mv0 = -1;
  int mv0value = -1;

  Print("Registering with network thread.\n",0,0,0);
  Register();
  Print("Done Registering with network thread.\n",0,0,0);

  Print("Creating lock with name \"lockOne\"\n",0,0,0);
  lock0 = CreateLock("lockOne");
  Print("Created lock with name \"lockOne\"\n",0,0,0);
  
  Print("Acquiring lock0\n",0,0,0);
  Acquire(lock0);
  Print("Acquired lock0\n",0,0,0);

  Print("Creating MV with name \"mvOne\"\n",0,0,0);
  mv0 = CreateMV("mvOne");
  Print("Created MV with name \"mvOne\" and ID=%d\n",mv0,0,0);

  
  mv0value = GetMV(mv0);
  Print("Current value of \"mvOne\" =%d\n",mv0value,0,0);

  mv0value++;

  Print("Setting value of \"mvOne\" to %d\n",mv0value,0,0);
  SetMV(mv0,mv0value);

  mv0value = GetMV(mv0);
  Print("New value of \"mvOne\" =%d\n",mv0value,0,0);
  
  Print("Releasing lock0\n",0,0,0);
  Release(lock0);

}
コード例 #12
0
void main()
{
	int lck1, lck2,cv1,cv2, mv1, setMvValue=-1, getMvValue =-1, arrayIndex=1;

	Print("\n  TC10_1 ::Multiple creation of same MV by diff userprog's. \n\0",1,1,1);

	lck1 = CreateLock("lock1", 5);

	Acquire(lck1);

	cv1 = CreateCV("cv1", 3);

	mv1 = CreateMV("mv1", 3, 1);
	Print("\n TC10_1:: MV name 'mv1' having Index '%d', of Array Size 1 Created. \n\0",mv1,1,1);

	Print("\n TC10_1:: Setting value for MV name 'mv1' at location '%d', at its Array Index '0'\n\0",mv1,1,1);
	SetMV(mv1, 0, 5);

	getMvValue = GetMV(mv1, 0);
	Print("\n TC10_1:: GetMV gets: '%d' for 'mv1', Array Index '0'. \n\0",getMvValue,1,1);

	Print("\nTC10_1 :: Going on wait on 'cv1' using 'lock1' that is acquired. Now run the 'tc10_2' file. \n",1,1,1);
	Wait(cv1,lck1);
	Print("\nTC10_1 :: Have been signalled on 'cv1' using 'lock1'.\n",1,1,1);

	Release(lck1);

	DeleteCV(cv1);

	DeleteLock(lck1);

	DeleteMV(mv1);

	Print("\n Reached end. value returned is %d\n\0",lck1,1,1);
	Exit(0);
}
コード例 #13
0
ファイル: mv_1_1.c プロジェクト: achinksinghal/CSCI_402
void main()
{
	int i=0;

	CreateMV("TC\0");
	SetMV("TC\0", 1);

	CreateMV("TCN\0");
	SetMV("TCN\0", -1);

	CreateMV("CU\0");
	SetMV("CU\0", 3);

	CreateMV("CC\0");
	SetMV("CC\0", -1);
	
	CreateMV("TT\0");
	SetMV("TT\0", -1);
	
	CreateMV("CN\0");
	SetMV("CN\0", -1);

	CreateMV("CG\0");
	SetMV("CG\0", -1);

        CreateMV("NTT\0");
        SetMV("NTT\0", 0);
        CreateMV("SIM\0");
        SetMV("SIM\0", 1);

	CreateMV("Z\0");
	SetMV("Z\0", 0);
			
	Exec("../test/man", 11, 16); /* starting manager*/

	CreateMV("EP1\0");
	CreateMV("EP2\0");
	SetMV("EP1\0", 0);
	SetMV("EP2\0", 0);

	while(GetMV("Z\0") == 0)
	{
		 Yield();
		 Yield();
		 Yield();
		 Yield();
		 Yield();
	}
	Exec("../test/tc", 10, 2); /*starting ticket clerk*/
	Exec("../test/cc", 10, 13); /*starting concession clerk*/
	Exec("../test/tt", 10, 14); /*starting ticket taker*/
	Exec("../test/mt", 10, 15); /*starting movie technician*/ 
	for(i = 3; i < 13; i++)
	{
		Exec("../test/cust", 12, i); /*starting customers*/
	}
	
	Exit(0);	
	
}
コード例 #14
0
ファイル: threadtest.c プロジェクト: meldefon/OSsome
void createServerMVs(int numCustomers, int numberOfSenators) {
	int i;
	/*global shared data between the clerks that are used for filing purposes */
	numCustomersLeft = CreateMV("numCustomersLeft", 16, 1);
	bribesEnabled = CreateMV("bribesEnabled", 13, 1);

	customersWithCompletedApps = CreateMV("customersWithCompletedApps", 26, numCustomers);
	customersWithCompletedPics = CreateMV("customersWithCompletedPics", 26, numCustomers);
	passportClerkChecked = CreateMV("passportClerkChecked", 20, numCustomers);
	cashierChecked = CreateMV("cashierChecked", 14, numCustomers);
	gottenPassport = CreateMV("gottenPassport", 14, numCustomers);
	cashReceived = CreateMV("cashReceived", 12, numCustomers);

	appClerkCurrentCustomer = CreateMV("appClerkCurrentCustomer", 23, numCustomers);
	pictureClerkCurrentCustomer = CreateMV("pictureClerkCurrentCustomer", 27, numCustomers);
	passportClerkCurrentCustomer = CreateMV("passportClerkCurrentCustomer", 28, numCustomers);
	cashierCurrentCustomer = CreateMV("cashierCurrentCustomer", 22, numCustomers);

	senatorLock = CreateLock("senatorLock", 11);
	senatorCV = CreateCondition("senatorCV", 9);
	isSenator = CreateMV("isSenator", 9, numCustomers);
	senatorWorking = CreateMV("senatorWorking", 14, 1);
	clerksCanWork = CreateMV("clerksCanWork", 13, 1);

	newCustomerId = CreateMV("newCustomerId", 13, 1);
	newCustomerIdLock = CreateLock("newCustomerIdLock", 17);

	/*Initialize everything*/
		
	/*
	numCustomersLeft = size;
	bribesEnabled = 1;
	newCustomerId = 0;
	*/

	SetMV(numCustomersLeft, 0, numCustomers);
	SetMV(bribesEnabled, 0, 1);
	SetMV(newCustomerId, 0, 0);

	for(i = 0; i < numCustomers; i++) {

		/*
		customersWithCompletedApps[i] = 0;
		customersWithCompletedPics[i] = 0;
		passportClerkChecked[i] = 0;
		cashierChecked[i] = 0;
		gottenPassport[i] = 0;
		cashReceived[i] = 0;
		*/

		SetMV(customersWithCompletedApps, i, 0);
		SetMV(customersWithCompletedPics, i, 0);
		SetMV(passportClerkChecked, i, 0);
		SetMV(cashierChecked, i, 0);
		SetMV(gottenPassport, i, 0);
		SetMV(cashReceived, i, 0);

		if(i < numCustomers-numberOfSenators) {
			SetMV(isSenator, i, 0); /*isSenator[i]= 0;*/
		} else {
			SetMV(isSenator, i, 1);/*isSenator[i]= 1;*/
		}
	}

	/* 
	senatorWorking = NULL;
	clerksCanWork = 1;
	*/

	SetMV(senatorWorking, 0, NULL);
	SetMV(clerksCanWork, 0, 1);
}
コード例 #15
0
int
main()
{
	int lockId, lockStatus, cvId, mvStatus, mvId, mvValue, lockId1, lockId2;

	WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1);

	lockId = CreateLock("lock1",5);
	if(lockId == -1)
	{
		WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nLock Created, Lock Id returned by the server is : %d\n\0", lockId, -1, -1);
	}

	WriteToConsole("\nCreating a CV\n\0", -1, -1, -1);

	cvId = CreateCV("cv1",3);
	if(cvId == -1)
	{
		WriteToConsole("\nError Occurred while creating CV. Exiting program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nCV Created, CV Id returned by the server is : %d\n\0", cvId, -1, -1);
	}

	WriteToConsole("\nCreating a MV\n\0", -1, -1, -1);

	mvId = CreateMV("mv1",3, 5);
	if(mvId == -1)
	{
		WriteToConsole("\nError Occurred while creating MV. Exiting program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nMV Created, MV Id returned by the server is : %d\n\0", mvId, -1, -1);
	}


	WriteToConsole("\nSetting MV to 100\n", -1, -1, -1);
	mvStatus = SetMV(mvId, 1, 100);
	if(mvStatus == -1)
	{
		WriteToConsole("\nFailed to Set MV. Exiting Program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nMV set successfully.\n\0", -1, -1, -1);
	}

	WriteToConsole("\nDeleting MV\n", -1, -1, -1);
	mvStatus = DeleteMV(mvId);
	if(mvStatus == -1)
	{
		WriteToConsole("\nFailed to Delete MV. Exiting Program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nMV deleted successfully.\n\0", -1, -1, -1);
	}

	WriteToConsole("\nTrying to fetch value from MV which is deleted : %d\n\0",mvId,-1,-1);
	mvValue = GetMV(mvId+25, 1);
	if(mvValue == -1)
	{
		WriteToConsole("\nInvalid mv Id. Exiting Program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nAbnormal Execution\n\0", -1, -1, -1);
	}

   Exit(0);
}
コード例 #16
0
ファイル: cc.c プロジェクト: achinksinghal/CSCI_402
/*
 * wrapper functions
 * for monitor variables
 * */
void createMv(MV *mv)
{
	mv->index = CreateMV(mv->name);
}
コード例 #17
0
ファイル: threadtest.c プロジェクト: meldefon/OSsome
void initialize(struct Monitor *m, int clerkType_, int size) {
	int i;
	char* lockName;
	int nameLength;

	nameLength = 50;

	if(clerkType_ == 0) {
		m->lineLock = CreateLock("lineLock0", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock0", 15);
		m->newClerkId = CreateMV("newClerkId0", 11, 1);
		m->clerkType = CreateMV("clerkType0", 10, 1);
		m->lineCV = CreateMV("lineCV0", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV0", 12, size);
		m->senLineCV = CreateMV("senLineCV0", 10, size);
		m->limboLineCV = CreateMV("limboLineCV0", 12, size);
		m->clerkLock = CreateMV("clerkLock0", 10, size);
		m->clerkCV = CreateMV("clerkCV0", 8, size);
		m->breakCV = CreateCondition("breakCV0", 8);
		m->lineCount = CreateMV("lineCount0", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount0", 15, size);
		m->senLineCount = CreateMV("senLineCount0", 13, size);
		m->clerkState = CreateMV("clerkState0", 11, size);
		m->numOfClerks = CreateMV("numOfClerks0", 12, 1);
		m->cashReceived = CreateMV("cashReceived0", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer0", 17, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo0", 20, 1);
		lockName = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
	} else if(clerkType_ == 1) {
		m->lineLock = CreateLock("lineLock1", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock1", 15);
		m->newClerkId = CreateMV("newClerkId1", 11, 1);
		m->clerkType = CreateMV("clerkType1", 10, 1);
		m->lineCV = CreateMV("lineCV1", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV1", 12, size);
		m->senLineCV = CreateMV("senLineCV1", 10, size);
		m->limboLineCV = CreateMV("limboLineCV0", 12, size);
		m->clerkLock = CreateMV("clerkLock1", 10, size);
		m->clerkCV = CreateMV("clerkCV1", 8, size);
		m->breakCV = CreateCondition("breakCV1", 8);
		m->lineCount = CreateMV("lineCount1", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount1", 15, size);
		m->senLineCount = CreateMV("senLineCount1", 13, size);
		m->clerkState = CreateMV("clerkState1", 11, size);
		m->numOfClerks = CreateMV("numOfClerks1", 12, 1);
		m->cashReceived = CreateMV("cashReceived1", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer1", 16, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo1", 20, 1);
		lockName = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
	} else if(clerkType_ == 2) {
		m->lineLock = CreateLock("lineLock2", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock2", 15);
		m->newClerkId = CreateMV("newClerkId2", 11, 1);
		m->clerkType = CreateMV("clerkType2", 10, 1);
		m->lineCV = CreateMV("lineCV2", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV2", 12, size);
		m->senLineCV = CreateMV("senLineCV2", 10, size);
		m->limboLineCV = CreateMV("limboLineCV2", 12, size);
		m->clerkLock = CreateMV("clerkLock2", 10, size);
		m->clerkCV = CreateMV("clerkCV2", 8, size);
		m->breakCV = CreateCondition("breakCV2", 8);
		m->lineCount = CreateMV("lineCount2", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount2", 15, size);
		m->senLineCount = CreateMV("senLineCount2", 13, size);
		m->clerkState = CreateMV("clerkState2", 11, size);
		m->numOfClerks = CreateMV("numOfClerks2", 12, 1);
		m->cashReceived = CreateMV("cashReceived2", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer2", 16, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo2", 20, 1);
		lockName = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";
	} else if(clerkType_ == 3) {
		m->lineLock = CreateLock("lineLock3", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock3", 15);
		m->newClerkId = CreateMV("newClerkId3", 11, 1);
		m->clerkType = CreateMV("clerkType3", 10, 1);
		m->lineCV = CreateMV("lineCV3", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV3", 12, size);
		m->senLineCV = CreateMV("senLineCV3", 10, size);
		m->limboLineCV = CreateMV("limboLineCV3", 12, size);
		m->clerkLock = CreateMV("clerkLock3", 10, size);
		m->clerkCV = CreateMV("clerkCV3", 8, size);
		m->breakCV = CreateCondition("breakCV3", 8);
		m->lineCount = CreateMV("lineCount3", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount3", 15, size);
		m->senLineCount = CreateMV("senLineCount3", 13, size);
		m->clerkState = CreateMV("clerkState3", 11, size);
		m->numOfClerks = CreateMV("numOfClerks3", 12, 1);
		m->cashReceived = CreateMV("cashReceived3", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer3", 16, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo3", 20, 1);
		lockName = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD";
	}
	
	SetMV(m->newClerkId, 0, 0);
	SetMV(m->numOfClerks, 0, size);
	SetMV(m->clerkType, 0, clerkType_);
	SetMV(m->numCustomersInLimbo, 0, 0);
	SetMV(m->cashReceived, 0, 0);

	for (i = 0; i < size; i++) {
		/*
		m->lineCV[i] = CreateCondition(lockName, nameLength);
		m->clerkLock[i] = CreateLock(lockName, nameLength);
		m->clerkCV[i] = CreateCondition(lockName, nameLength);
		m->bribeLineCV[i] = CreateCondition(lockName, nameLength);
		m->senLineCV[i] = CreateCondition(lockName, nameLength);
		*/

		SetMV(m->lineCV, i, CreateCondition(lockName, nameLength));
		SetMV(m->clerkLock, i, CreateLock(lockName, nameLength));
		nameLength--;
		SetMV(m->clerkCV, i, CreateCondition(lockName, nameLength));
		nameLength--;
		SetMV(m->bribeLineCount, i, CreateCondition(lockName, nameLength));
		nameLength--;
		SetMV(m->senLineCV, i, CreateCondition(lockName, nameLength));
		nameLength--;

		/*
		m->lineCount[i] = 0;
		m->bribeLineCount[i] = 0;
		m->senLineCount[i] = 0;
		m->clerkState[i] = 0;
		m->currentCustomer[i] = -1;
		*/

		SetMV(m->lineCount, i, 0);
		SetMV(m->bribeLineCount, i, 0);
		SetMV(m->senLineCount, i, 0);
		SetMV(m->clerkState, i, 0);
		SetMV(m->currentCustomer, i, -1);
	}
}
コード例 #18
0
ファイル: cashier.c プロジェクト: shengzhc/CSCi402
void doCreate() 
{
    int t;
    wrWaitingCount = CreateMV("wrwc", sizeof("wrwc")/sizeof(char), 1);
    wrnServiceId = CreateMV("wsid", sizeof("wsid")/sizeof(char), 1);
    wrnExamSheet = CreateMV("wes", sizeof("wes")/sizeof(char), 2);
    wrnCompleteESList = CreateMV("wrnces", sizeof("wrnces")/sizeof(char), 64);
    nwrnWaitingCount = CreateMV("nwwc", sizeof("nwwc")/sizeof(char), 1);
    nwrnExamSheet = CreateMV("nwes", sizeof("nwes")/sizeof(char), 1);
    nwrnId = CreateMV("nwid", sizeof("nwid")/sizeof(char), 1);
    pid = CreateMV("pid", sizeof("pid")/sizeof(char), 1);
    wrnTask = CreateMV("wt", sizeof("wt")/sizeof(char), 1);
    esStack = CreateMV("ess", sizeof("ess")/sizeof(char), 18*256);
    broadCastId = CreateMV("bcid", sizeof("bcid")/sizeof(char), 1);
    bcIdStatus = CreateMV("bcis", sizeof("bcis")/sizeof(char), 1);
    examRoomsLockMV = CreateMV("erlmv", sizeof("erlmv")/sizeof(char), 6);
    SetMV(examRoomsLockMV, 0, 5);
    examRoomsCVMV = CreateMV("ercmv", sizeof("ercmv")/sizeof(char), 6);
    SetMV(examRoomsCVMV, 0, 5);
    doctWaitingLockMV = CreateMV("dwlm", sizeof("dwlm")/sizeof(char), 3);
    SetMV(doctWaitingLockMV, 0, 2);
    docStatus = CreateMV("ds", sizeof("ds")/sizeof(char), 3);
    SetMV(docStatus, 0, 2);
    doctWaitingCVMV = CreateMV("dwcm", sizeof("dwcm")/sizeof(char), 3);
    SetMV(doctWaitingCVMV, 0, 2);
    ndocESNo = CreateMV("nesn", sizeof("nesn")/sizeof(char), 3);
    SetMV(ndocESNo, 0, 2);
    wallPackets = CreateMV("wp", sizeof("wp")/sizeof(char), 6);
    SetMV(wallPackets, 0, 5);
    docid = CreateMV("di", sizeof("di")/sizeof(char), 1);
    xid = CreateMV("xid", sizeof("xid")/sizeof(char), 1);    
    xrayRoomsLockMV = CreateMV("xrlmv", sizeof("xrlmv")/sizeof(char), 3);
    SetMV(xrayRoomsLockMV, 0, 2);
    xrayRoomsCVMV = CreateMV("xrcmv", sizeof("xrcmv")/sizeof(char), 3);
    SetMV(xrayRoomsCVMV, 0, 2);
    xrayRoomsES = CreateMV("xres", sizeof("xres")/sizeof(char), 3);
    SetMV(xrayRoomsES, 0, 2);
    xrayRoomsStatus = CreateMV("xrs", sizeof("xrs")/sizeof(char), 3);
    SetMV(xrayRoomsStatus, 0, 2);
    xrayWaitingES = CreateMV("xwes", sizeof("xwes")/sizeof(char), 64);
    cashWaitingCount = CreateMV("cwc", sizeof("cwc")/sizeof(char), 1);
    cashExamSheet = CreateMV("ces", sizeof("ces")/sizeof(char), 1);
    nid = CreateMV("nid", sizeof("nid")/sizeof(char), 1);
    examRoomsStatus = CreateMV("ers", sizeof("ers")/sizeof(char), 6);
    SetMV(examRoomsStatus, 0, 5);
    cabinetCount = CreateMV("cac", sizeof("cac")/sizeof(char), 1);
    waitingRoomLock = CreateLock("wrl", sizeof("wrl")/sizeof(char));
    wrnLock = CreateLock("wrnl", sizeof("wrnl")/sizeof(char));
    nwrnLock = CreateLock("nwrnl", sizeof("nwrnl")/sizeof(char));
    t = CreateLock("erl1", sizeof("erl1")/sizeof(char));
    SetMV(examRoomsLockMV, 1, t);
    t = CreateLock("erl2", sizeof("erl2")/sizeof(char));
    SetMV(examRoomsLockMV, 2, t);
    t = CreateLock("erl3", sizeof("erl3")/sizeof(char));
    SetMV(examRoomsLockMV, 3, t);
    t = CreateLock("erl4", sizeof("erl4")/sizeof(char));
    SetMV(examRoomsLockMV, 4, t);
    t = CreateLock("erl5", sizeof("erl5")/sizeof(char));
    SetMV(examRoomsLockMV, 5, t);
    broadCastIdLock = CreateLock("bcil", sizeof("bcil")/sizeof(char));
    cashWaitingLock = CreateLock("cwl", sizeof("cwl"));
    cashLock = CreateLock("cl", sizeof("cl")/sizeof(char));
    pidLock = CreateLock("pl", sizeof("pl")/sizeof(char));
    t = CreateLock("dwl1", sizeof("dwl1")/sizeof(char));
    SetMV(doctWaitingLockMV, 1, t);
    t = CreateLock("dwl2", sizeof("dwl2")/sizeof(char));
    SetMV(doctWaitingLockMV, 2, t);
    didLock = CreateLock("dl", sizeof("dl")/sizeof(char));
    t = CreateLock("xrl1", sizeof("xrl1")/sizeof(char));
    SetMV(xrayRoomsLockMV, 1, t);
    t = CreateLock("xrl2", sizeof("xrl2")/sizeof(char));
    SetMV(xrayRoomsLockMV, 2, t);
    xidLock = CreateLock("xl", sizeof("xl")/sizeof(char));
    nidLock = CreateLock("nl", sizeof("nl")/sizeof(char));
    ersStatusLock = CreateLock("ersl", sizeof("ersl")/sizeof(char));
    xrayWaitingLock = CreateLock("xwl", sizeof("xwl")/sizeof(char));
    xrayRoomsStatusLock = CreateLock("xrsl", sizeof("xrsl")/sizeof(char));
    cabinetLock = CreateLock("cl", sizeof("cl")/sizeof(char));
    waitingRoomCV = CreateCondition("wrc", sizeof("wrc")/sizeof(char));
    nwrnCV = CreateCondition("nwrnc", sizeof("nwrnc")/sizeof(char));
    wrnCV = CreateCondition("wrnc", sizeof("wrnc")/sizeof(char));
    nwrnWaitingCV = CreateCondition("nwc", sizeof("nwc")/sizeof(char));
    t = CreateCondition("erc1", sizeof("erc1")/sizeof(char));
    SetMV(examRoomsCVMV, 1, t);
    t = CreateCondition("erc2", sizeof("erc2")/sizeof(char));
    SetMV(examRoomsCVMV, 2, t);
    t = CreateCondition("erc3", sizeof("erc3")/sizeof(char));
    SetMV(examRoomsCVMV, 3, t);
    t = CreateCondition("erc4", sizeof("erc4")/sizeof(char));
    SetMV(examRoomsCVMV, 4, t);
    t = CreateCondition("erc5", sizeof("erc5")/sizeof(char));
    SetMV(examRoomsCVMV, 5, t);    
    t = CreateCondition("dwc1", sizeof("dwc1")/sizeof(char));
    SetMV(doctWaitingCVMV, 1, t);
    t = CreateCondition("dwc2", sizeof("dwc2")/sizeof(char));
    SetMV(doctWaitingCVMV, 2, t);
    t = CreateCondition("xrc1", sizeof("xrc1")/sizeof(char));
    SetMV(xrayRoomsCVMV, 1, t);
    t = CreateCondition("xrc2", sizeof("xrc2")/sizeof(char));
    SetMV(xrayRoomsCVMV, 2, t);
    cashWaitingCV = CreateCondition("cwc", sizeof("cwc")/sizeof(char));
    cashCV = CreateCondition("cc", sizeof("cc")/sizeof(char));
    broadCastIdCV = CreateCondition("bcicv", sizeof("bcicv")/sizeof(char));
    bcIdWaitingCV = CreateCondition("bwc", sizeof("bwc")/sizeof(char));
}
コード例 #19
0
void Initialize()
{
	int i,j;
	int localGroupSize;
	int localNumberOfGroups;
	int concessionClerkStateRV;
	int ticketClerkStateRV;
	int ttTakingTicketsRV;
	int ticketTakerStateRV;
	int ticketTakerGroupIndicatorRV;
	int ticketTakerTheatreCountStatusRV;
	int localTotalCustomerNumber;
	int availableCustSizeForGroupArrRV;


	CreateLock("InitLock");

	Acquire("InitLock");

/*	int concessionClerkState[GlobalnoOfCC];				/*Stores the Concession Clerks State*/

	concessionClerkStateRV = CreateMV("ccState",GlobalnoOfCC);
	if(concessionClerkStateRV==1)
	{
		for(i=0;i<GlobalnoOfCC;i++)
		{
			SetMV("ccState",i,1);
		}
	}

/*	int ticketClerkState[GlobalnoOfTC];					/* Stores the state of each Ticket Clerk */
	
	ticketClerkStateRV = CreateMV("ticketClerkState",GlobalnoOfTC);
	if(ticketClerkStateRV==1)
	{
		for(i=0;i<GlobalnoOfTC;i++)
		{
			SetMV("ticketClerkState",i,1);
		}
	}

/*	int ttTakingTickets;							/*Stores if TT are taking tickets*/

	ttTakingTicketsRV = CreateMV("ttTakingTickets",1);
	if(ttTakingTicketsRV==1)
	{
		SetMV("ttTakingTickets",0,1);
	}



/*	int ticketTakerState[GlobalnoOfTT];					/*State of each TT(Ticket Taker)*/

	ticketTakerStateRV = CreateMV("ticketTakerState",GlobalnoOfTT);
	if(ticketTakerStateRV==1)
	{
		for(i=0;i<GlobalnoOfTT;i++)
		{
			SetMV("ticketTakerState",i,1);
		}
	}


/*	int ticketTakerGroupIndicator[GlobalnoOfTT];			/*Indicates a group whether to go inside or wait in lobby*/

	ticketTakerGroupIndicatorRV = CreateMV("TTGroupInd",GlobalnoOfTT);
	if(ticketTakerGroupIndicatorRV==1)
	{
		for(i=0;i<GlobalnoOfTT;i++)
		{
			SetMV("TTGroupInd",i,1);
		}
	}


/*	int ticketTakerTheatreCountStatus=1;			/*count for the ticket taker*/

	ticketTakerTheatreCountStatusRV = CreateMV("ttTheCount",1);
	if(ticketTakerTheatreCountStatusRV==1)
	{
		SetMV("ttTheCount",0,1);
	}

	/*	int availableCustSizeForGroupArr[50];		/*Array for each customer to determine its group*/
	availableCustSizeForGroupArrRV=CreateMV("avCustGrpArr",50);
	for(i=0;i<GlobalnoOfGroups;i++)
	{
		if(availableCustSizeForGroupArrRV==1)
		{
			SetMV("avCustGrpArr",i,GlobalGroupNormalCustSize);
		}
	}

	Release("InitLock");

	/*******************************************************************************************************/

/*	int totalCustomerNumber;						/* Total Number of Customers */
	CreateMV("totCustNum",1);

/*	int noOfGroups;								/* Stores the number of groups generated */
	CreateMV("noOfGroups",1);
	SetMV("noOfGroups",0,GlobalnoOfGroups);						/* %%%%%%%%%%%%%% For the time being. %%%%%%%%%%%%%%%% */

/*	int noOfTC;*/
	CreateMV("noOfTC",1);
	SetMV("noOfTC",0,GlobalnoOfTC);

/*	int noOfCC;*/
	CreateMV("noOfCC",1);
	SetMV("noOfCC",0,GlobalnoOfCC);

/*	int noOfTT;*/
	CreateMV("noOfTT",1);
	SetMV("noOfTT",0,GlobalnoOfTT);

/*	int noOfCustomers;*/
	CreateMV("noOfCustomers",1);

/*	int groupSize;*/
	CreateMV("groupSize",1);

/*	int totalAmtTicket;*/							/* Total Amount Variable */
	CreateMV("totalAmtTicket",1);

/*	int noOfTickets[GlobalnoOfTC];						/* Keep track of no. of tickets sold by each clerk */
	CreateMV("noOfTickets",GlobalnoOfTC);

/*	int ticketClerkAmount[GlobalnoOfTC];				/* Amount given by customer at each TicketClerk */
	CreateMV("ticketClerkAmount",GlobalnoOfTC);

/*	int totalAmountTicketClerk[GlobalnoOfTC];			/* Amount deposited at each TicketClerk */
	CreateMV("totAmtTC",GlobalnoOfTC);

/*	int ticketClerkOnBreak=0;						/* Count of the Ticket Clerks on break*/
	CreateMV("tcOnBreak",1);

/*	int managerTcWait[GlobalnoOfTC];					/* Manager signal for each Ticket Clerk*/
	CreateMV("managerTcWait",GlobalnoOfTC);

/*	int custFindLineTC[GlobalnoOfTC];					/* Variable to say that broadcast customers*/
	CreateMV("custFindLineTC",GlobalnoOfTC);

/*	int reFindLineTC[GlobalnoOfTC];						/*Flag to say that the customer has to find line again*/
	CreateMV("reFindLineTC",GlobalnoOfTC);

/*	int totalAmountConcessionClerk[GlobalnoOfCC];		/*Total Amount stored by all Concession Clerks*/
	CreateMV("totAmtCC",GlobalnoOfCC);


/*	int concessionClerkLineCount[GlobalnoOfCC];			/*Stores the Concession Clerks Line Count*/
	CreateMV("ccLineCnt",GlobalnoOfCC);



	/* $$$$$$$$ Ticket Clerk Variables $$$$$$$$ */



/*	int ticketClerkLineCount[GlobalnoOfTC];				/* Stores the Line Count of each Ticket Clerk */
	CreateMV("tcLineCnt",GlobalnoOfTC);

/*	int ticketClerkLineCVInt[GlobalnoOfTC]; */

/*	char ticketClerkLineCVChar[GlobalnoOfTC][200]; */
	for(i=0;i<GlobalnoOfTC;i++)
	{
		Sprint(ticketClerkLineCVChar[i],"TCLineCV",i);			/*changed this $$$$$$$$$$$$$$$$$$$$*/
		CreateCV(ticketClerkLineCVChar[i]);
	}


/*	int ticketClerkLineLockInt; */
	CreateLock("tcLineLock");

/*	int totalAmtTicketLockInt; */
	CreateLock("toAmtTktLck");

/*	int ticketClerkCVInt[GlobalnoOfTC]; */

/*	char ticketClerkCVChar[GlobalnoOfTC][200]; */
	for(i=0;i<GlobalnoOfTC;i++)
	{
		Sprint(ticketClerkCVChar[i],"TCCV",i);	
		CreateCV(ticketClerkCVChar[i]);
	}

/*	int ticketClerkLockInt[GlobalnoOfTC]; */

/*	char ticketClerkLockChar[GlobalnoOfTC][200]; */
	for(i=0;i<GlobalnoOfTC;i++)
	{
		Sprint(ticketClerkLockChar[i],"TCLock",i);	
		CreateLock(ticketClerkLockChar[i]);
	}


/*	int concessionClerkLineCVInt[GlobalnoOfCC]; */

/*	char concessionClerkLineCVChar[GlobalnoOfCC][200]; */
	for(i=0;i<GlobalnoOfCC;i++)
	{
		Sprint(concessionClerkLineCVChar[i],"CCLineCV",i);	
		CreateCV(concessionClerkLineCVChar[i]);
	}

/*	int concessionClerkLineLockInt; */
	CreateLock("ccLineLock");

/*	int totalAmtPopSodaLockInt; */
	CreateLock("toAmtPopLck");

/*	int noOfSoda[GlobalnoOfCC];							/*customer Vaiable to store soda value on a Concession Clerk*/
	CreateMV("noOfSoda",GlobalnoOfCC);

/*	int noOfPopcorn[GlobalnoOfCC];						/*customer Vaiable to store popcorn value on a Concession Clerk*/
	CreateMV("noOfPopcorn",GlobalnoOfCC);

/*	int totalMoneySoda;								/*total money by Soda*/
	CreateMV("totalMoneySoda",1);

/*	int totalMoneyPopcorn;							/*total money by popcorn*/
	CreateMV("totalMoneyPopcorn",1);

/*	int amountSoda[GlobalnoOfCC];							/*Amount customer has to pay for Soda*/
	CreateMV("amountSoda",GlobalnoOfCC);

/*	int amountPopcorn[GlobalnoOfCC];						/*Amount customer has to pay for Popcorn*/
	CreateMV("amountPopcorn",GlobalnoOfCC);

/*	int concessionClerkCVInt[GlobalnoOfCC]; */

/*	char concessionClerkCVChar[GlobalnoOfTC][200]; */
	for(i=0;i<GlobalnoOfTC;i++)
	{
		Sprint(concessionClerkCVChar[i],"CCCV",i);	
		CreateCV(concessionClerkCVChar[i]);
	}

/*	int concessionClerkLockInt[GlobalnoOfCC]; */

/*	char concessionClerkLockChar[GlobalnoOfCC][200]; */
	for(i=0;i<GlobalnoOfCC;i++)
	{
		Sprint(concessionClerkLockChar[i],"CCLock",i);	
		CreateLock(concessionClerkLockChar[i]);
	}

/*	int conClerkOnBreak=0;							/*Count of CCs on break*/
	CreateMV("conClerkOnBreak",1);

/*	int managerCcWait[GlobalnoOfCC];						/*Flag for wait of CC*/
	CreateMV("managerCcWait",GlobalnoOfCC);

/*	int custFindLineCC[GlobalnoOfCC];						/*Variable of CC to tell customer to find line*/
	CreateMV("custFindLineCC",GlobalnoOfCC);

/*	int reFindLineCC[GlobalnoOfCC];						/*Flag for customer to find line again*/
	CreateMV("reFindLineCC",GlobalnoOfCC);



	/*********Variables for Technician Manager and Customer Interaction*********/

/*	int movieTheaterLockInt; */
	CreateLock("movieTheaterLock");

/*	int movieTheaterCVInt; */
	CreateCV("movieTheaterCV");

/*	int custEnteredTheater;							/*Count of Cust entering the theater room*/
	CreateMV("custEnteredTheater",1);

/*	int custLeavingTheater;							/*Count of Cust leaving the theater room*/
	CreateMV("custLeavingTheater",1);



/*	int isMovieOver;								/* Stores the movie state*/
	CreateMV("isMovieOver",1);

/*	int movieTechLockInt;							/* Lock for Movie Technician */
	CreateLock("movieTechLock");

/*	int movieTechCVInt;								/* Conditon Variable for Technician*/
	CreateCV("movieTechCV");

/*	int custFinalExitLockInt;						/* Lock for count of finally exiting customers*/
	CreateLock("custFinalExitLock");

/*	int custFinalExitCount;							/*Variable for count of finally exiting customers*/
	CreateMV("custFinalExitCount",1);


	
	/*/////////////////////////////Ticket Taker//////////////////////////////////*/

/*	int custTicketsApproved=0;						/*Stores the no of tickets approved to go inside theater room*/
	CreateMV("custTicketsApproved",1);



/*	int ticketTakerLineCount[GlobalnoOfTT];				/*Stores the Line count of each TT*/
	CreateMV("ttLineCnt",GlobalnoOfTT);



/*	int custNoOfTicket[GlobalnoOfTT];						/*Number of tickets of each group*/
	CreateMV("custNoOfTicket",GlobalnoOfTT);



/*	int ticketTakerLineLockInt;						/* Lock for the TT Line*/
	CreateLock("ttLineLock");

/*	int ticketTakerLockInt[GlobalnoOfTT];					/* Lock for each TT*/

/*	char ticketTakerLockChar[GlobalnoOfTT][200]; */
	for(i=0;i<GlobalnoOfTT;i++)
	{
		Sprint(ticketTakerLockChar[i],"TTLock",i);	
		CreateLock(ticketTakerLockChar[i]);
	}

/*	int ticketTakerManagerLockInt;					/* TicketTaker Manager Lock*/
	CreateLock("ttMgrLock");

/*	int custTicketsApprovedLockInt;					/* Lock for total tickets approved to go inside*/
	CreateLock("TktsAppLock");

/*	int ticketTakerLineCVInt[GlobalnoOfTT];				/* CV for each TT Line*/

/*	char ticketTakerLineCVChar[GlobalnoOfTT][200]; */
	for(i=0;i<GlobalnoOfTT;i++)
	{
		Sprint(ticketTakerLineCVChar[i],"TTLineCV",i);	
		CreateCV(ticketTakerLineCVChar[i]);
	}

/*	int ticketTakerCVInt[GlobalnoOfTT];					/* CV for each TT interaction*/

/*	char ticketTakerCVChar[GlobalnoOfTT][200]; */
	for(i=0;i<GlobalnoOfTT;i++)
	{
		Sprint(ticketTakerCVChar[i],"TTCV",i);	
		CreateCV(ticketTakerCVChar[i]);
	}

/*	int ticketTakerManagerCVInt;					/* CV for Technician */
	CreateCV("ttMgrCV");

/*	int customerLobbyCVInt;							/*CV for Lobby*/
	CreateCV("customerLobbyCV");

/*	int customerLobbyLockInt;						/*Lock for Lobby*/
	CreateLock("customerLobbyLock");

/*	int isTakingTickets;							/*Stores whether the TT is taking tickets or not*/
	CreateMV("isTakingTickets",1);

/*	int ttWaitShowOverLockInt[GlobalnoOfTT];				/*Lock for TT till the next show starts*/

/*	char ttWaitShowOverLockChar[GlobalnoOfTT][200]; */
	for(i=0;i<GlobalnoOfTT;i++)
	{
		Sprint(ttWaitShowOverLockChar[i],"ttWSOLock",i);	
		CreateLock(ttWaitShowOverLockChar[i]);
	}

/*	int ttWaitShowOverCVInt[GlobalnoOfTT];				/*CV for waiting of TT till next show start*/

/*	char ttWaitShowOverCVChar[GlobalnoOfTT][200]; */
	for(i=0;i<GlobalnoOfTT;i++)
	{
		Sprint(ttWaitShowOverCVChar[i],"ttWSOCV",i);	
		CreateCV(ttWaitShowOverCVChar[i]);
	}




	/***************************Variables for Group Interaction*********************************/

/*	int groupLockInt[GlobalnoOfGroups];						/*Group Lock for each group*/

/*	char groupLockChar[GlobalnoOfGroups][200]; */
	for(i=0;i<GlobalnoOfGroups;i++)
	{
		Sprint(groupLockChar[i],"groupLock",i);	
		CreateLock(groupLockChar[i]);
	}

/*	int groupCVInt[GlobalnoOfGroups];						/* CV for each group*/

/*	char groupCVChar[GlobalnoOfGroups][200]; */
	for(i=0;i<GlobalnoOfGroups;i++)
	{
		Sprint(groupCVChar[i],"groupCV",i);	
		CreateCV(groupCVChar[i]);
	}

/*	int canGoInsideTheater[GlobalnoOfGroups];				/*Stores whether Cust can go inside*/
	CreateMV("canGoInsideTheater",GlobalnoOfGroups);

/*	int canGoBathroom[GlobalnoOfGroups];						/*Stores whtehr cust can go to bathroom*/
	CreateMV("canGoBathroom",GlobalnoOfGroups);

/*	int counterAfterMuvi[GlobalnoOfGroups];					/* stores the count of cust got up after movie*/
	CreateMV("counterAfterMuvi",GlobalnoOfGroups);

/*	int counterAfterBathroom[GlobalnoOfGroups];				/* stores the count of cust going to bathroom*/
	CreateMV("ctrAfterBath",GlobalnoOfGroups);

/*	int bathroomLobbyCVInt[GlobalnoOfGroups];				/* CV for use when other cust has to wait when 1 goes to bathroom*/

/*	char bathroomLobbyCVChar[GlobalnoOfGroups][200]; */
	for(i=0;i<GlobalnoOfGroups;i++)
	{
		Sprint(bathroomLobbyCVChar[i],"bLobbyCV",i);	
		CreateCV(bathroomLobbyCVChar[i]);
	}

/*	int bathroomLockInt;							/* Lock for bathroom*/
	CreateLock("bathroomLock");

/*	int ttWaitingAfterFull[GlobalnoOfTT]; */
	CreateMV("ttWaitingAfterFull",GlobalnoOfTT);

/*	int managerWokeTT[GlobalnoOfTT];					/*manager waking up TT to start taking ticket*/
	CreateMV("managerWokeTT",GlobalnoOfTT);

/*	int countCustTT;							/*count of cust going to TT*/
	CreateMV("countCustTT",1);
	
/*	int total; */
	CreateMV("total",1);

/*	int totalHeadCust;							/*Count of all head customer*/
	CreateMV("totalHeadCust",1);

/*	int groupPopcorn[GlobalnoOfGroups];					/*popcorn by each group*/
	CreateMV("groupPopcorn",GlobalnoOfGroups);

/*	int groupSoda[GlobalnoOfGroups];						/* Soda ordered by each group*/
	CreateMV("groupSoda",GlobalnoOfGroups);

/*	int haveTickets[GlobalnoOfGroups];					/*Stores whtehr the head have tickets or not*/
	CreateMV("haveTickets",GlobalnoOfGroups);

/*	int givenFoodChoice[GlobalnoOfGroups];				/*sores whther give the food choice*/
	CreateMV("givenFoodChoice",GlobalnoOfGroups);

	/*Seat variabes*/
/*	int rowNo,columnNo;							/*row number and column number of seat*/
	CreateMV("rowNo",1);
	CreateMV("columnNo",1);

/*	int counterVal[GlobalnoOfGroups];					/*counter for each customer accessing seat*/
	CreateMV("counterVal",GlobalnoOfGroups);


/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */

/*	int movieRoomSeatNoArray[5][5];				/*array for storing seat avaible or not

	int movieRoomGrpNoArray[5][5];				/*array for storing seat assigned to which group
*/

/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */

/*	int sizeForGroupArr[50];					/*Storing the group size for each group*/
	CreateMV("sizeForGroupArr",50);


	/*Global Part for TC myIndex value*/

/*	int ticketClerkIndexLockInt; */
	CreateLock("ticketClerkIndexLock");

/*	int nextTCIndex=0; */
	CreateMV("nextTCIndex",1);


	/*Global Part for Customer value*/

/*	int groupNumberLockInt, customerNumberLockInt, groupSizeLockInt; */
	CreateLock("groupNumberLock");
	CreateLock("customerNumberLock");
	CreateLock("groupSizeLock");

/*	int nextGroupNumber=0, nextCustomerNumber=0, nextGroupSize=0; */
	CreateMV("nextGroupNumber",1);
	CreateMV("nextCustomerNumber",1);
	CreateMV("nextGroupSize",1);


	/*Global Part for CC myIndex value*/

/*	int concessionClerkIndexLockInt; */
	CreateLock("ccIndexLock");

/*	int nextCCIndex=0; */
	CreateMV("nextCCIndex",1);

/*	int determineCustGroupNumberLockInt; */
	CreateLock("custGrpNumLock");



	/*Global Part for TT myIndex value*/

/*	int ticketTakerIndexLockInt; */
	CreateLock("ticketTakerIndexLock");

/*	int nextTTIndex=0; */
	CreateMV("nextTTIndex",1);

/*	int checkFinalExitLockInt; */
	CreateLock("checkFinalExitLock");

/*	int finalExitFlag=0; */
	CreateMV("finalExitFlag",1);


/*	numberOfGroups=noOfGroups;*/								/*$$$$$$$$$$$$$$$$$ From Main Function $$$$$$$$$$$$$$$$$*/
	localNumberOfGroups=GetMV("noOfGroups",0);


/*	Acquire("InitLock");				/* ############################################################### */

/*	totalHeadCust=numberOfGroups;*/

	SetMV("totalHeadCust",0,localNumberOfGroups);


		SetMV("totCustNum",0,GlobalnoOfGroups*(GlobalGroupNormalCustSize+1));

	for(i=0;i<localNumberOfGroups;i++)
	{
/*		groupSize=Rand(5);*/
		/*localGroupSize = Rand(5);*/			/*$$$$$$$$$$$$$$$$$ Hardcoded to 0 $$$$$$$$$$$$$$$$$*/		
		localGroupSize=0;

		SetMV("groupSize",0,GlobalGroupNormalCustSize);


/*		sizeForGroupArr[i]=groupSize;								/*Assigning group size*/ 
		localGroupSize = GetMV("groupSize",0);
		SetMV("sizeForGroupArr",i,localGroupSize);

/*		availableCustSizeForGroupArr[i]=groupSize; */

/*		if(availableCustSizeForGroupArrRV==1)
		{
		SetMV("avCustGrpArr",i,localGroupSize);			//Removed from here to top, inside the lock.
		}
*/


/*		totalCustomerNumber++;*/
		localTotalCustomerNumber=GetMV("totCustNum",0);
	/*	SetMV("totCustNum",0,localTotalCustomerNumber+1);*/

		for (j=0;j<localGroupSize;j++ )
		{
/*			totalCustomerNumber++; */
		localTotalCustomerNumber=GetMV("totCustNum",0);
		/*	SetMV("totCustNum",0,localTotalCustomerNumber+1);*/

/*			Fork(Customer); */
		}
	
	}

/*	Release("InitLock");				/* ############################################################### */


/*	Release("InitLock"); */
}
コード例 #20
0
ファイル: tc.c プロジェクト: achinksinghal/CSCI_402
/*
 * wrapper functions for
 * monitor variables
 * */
void createMv(MV *mv)
{
	CreateMV(mv->name);

}
コード例 #21
0
void createVars() {
    int i;
    char * name;

    passengersFinished = CreateMV("passengersFinished",-1);
    passengersEaten = CreateMV("passengersEaten",-1);
    passengersSlept = CreateMV("passengersSlept",-1);

    passengerID = CreateMV("passengerID",-1);
    coachAttendantID = CreateMV("coachAttendantID",-1);
    porterID = CreateMV("porterID",-1);
    waiterID = CreateMV("waiterID",-1);
    chefID = CreateMV("chefID",-1);

    totalRevenue=CreateMV("totalRevenue",-1);
    ticketRevenue=CreateMV("ticketRevenue",-1);
    diningCarRevenue=CreateMV("diningCarRevenue",-1);
    waiterRevenue=CreateMV("waiterRevenue",-1);

    currentStop = CreateMV("currentStop",-1);
    passengersOnTrain = CreateMV("passengersOnTrain",-1);

    for(i = 0; i < 4; i++) {
        name = "foodStock  ";
        name[9] = (char)(i/10+48);
        name[10] = (char)(i%10+48);
        foodStock[i] = CreateMV(name,-1);

        name = "foodStockLow  ";
        name[12] = (char)(i/10+48);
        name[13] = (char)(i%10+48);
        foodStockLow[i] = CreateMV(name,-1);
    }

    nowStopped=CreateMV("nowStopped",-1);


    for(i = 0; i < PASSENGERS; i++) {
        name = "getOnStop  ";
        name[9] = (char)(i/10+48);
        name[10] = (char)(i%10+48);
        tickets[i].getOnStop = CreateMV(name,-1);
        name = "getOffStop  ";
        name[10] = (char)(i/10+48);
        name[11] = (char)(i%10+48);
        tickets[i].getOffStop = CreateMV(name,-1);
        name = "holder  ";
        name[6] = (char)(i/10+48);
        name[7] = (char)(i%10+48);
        tickets[i].holder = CreateMV(name,-1);
        name = "okToBoard  ";
        name[9] = (char)(i/10+48);
        name[10] = (char)(i%10+48);
        tickets[i].okToBoard = CreateMV(name,-1);
        name = "seatNumber  ";
        name[10] = (char)(i/10+48);
        name[11] = (char)(i%10+48);
        tickets[i].seatNumber = CreateMV(name,-1);
        name = "hasBedding  ";
        name[10] = (char)(i/10+48);
        name[11] = (char)(i%10+48);
        tickets[i].hasBedding = CreateMV(name,-1);
        name = "hasEaten  ";
        name[8] = (char)(i/10+48);
        name[9] = (char)(i%10+48);
        tickets[i].hasEaten = CreateMV(name,-1);
        name = "hasSlept  ";
        name[8] = (char)(i/10+48);
        name[9] = (char)(i%10+48);
        tickets[i].hasSlept = CreateMV(name,-1);
        name = "foodOrder  ";
        name[9] = (char)(i/10+48);
        name[10] = (char)(i%10+48);
        tickets[i].foodOrder = CreateMV(name,-1);
        name = "validFoodOrder  ";
        name[14] = (char)(i/10+48);
        name[15] = (char)(i%10+48);
        tickets[i].validFoodOrder = CreateMV(name,-1);
        name = "waiter  ";
        name[6] = (char)(i/10+48);
        name[7] = (char)(i%10+48);
        tickets[i].waiter = CreateMV(name,-1);
    }

    /* data for passenger/ticketChecker interactions*/
    for(i = 0; i < MAX_STOPS; i++) {
        name = "passengersWaitingToBoard  ";
        name[24] = (char)(i/10+48);
        name[25] = (char)(i%10+48);
        passengersWaitingToBoard[i] = CreateMV(name,-1);
    }
    ticketCheckerLineLength = CreateMV("ticketCheckerLineLength",-1);
    ticketCheckerAvailable = CreateMV("ticketCheckerAvailable",-1);
    ticketToCheckHolder = CreateMV("ticketToCheckHolder",-1);
    ticketToCheckGetOnStop = CreateMV("ticketToCheckGetOnStop",-1);
    ticketToCheckOkToBoard = CreateMV("ticketToCheckOkToBoard",-1);
    /*--end passenger/ticketChecker data*/

    /*data for CoachAttendant/Passenger interactions*/
    for(i = 0; i < COACH_ATTENDANTS; i++) {
        name = "coachAttendantRegularLineLength  ";
        name[31] = (char)(i/10+48);
        name[32] = (char)(i%10+48);
        coachAttendantRegularLineLength[i] = CreateMV(name,-1);
        name = "coachAttendantFirstLineLength  ";
        name[29] = (char)(i/10+48);
        name[30] = (char)(i%10+48);
        coachAttendantFirstLineLength[i] = CreateMV(name,-1);
        name = "coachAttendantAvailable  ";
        name[23] = (char)(i/10+48);
        name[24] = (char)(i%10+48);
        coachAttendantAvailable[i] = CreateMV(name,-1);

        name = "passengerTicketsHolder  ";
        name[22] = (char)(i/10+48);
        name[23] = (char)(i%10+48);
        passengerTicketsHolder[i] = CreateMV(name,-1);
        name = "passengerTicketsSeatNumber  ";
        name[26] = (char)(i/10+48);
        name[27] = (char)(i%10+48);
        passengerTicketsSeatNumber[i] = CreateMV(name,-1);

        name = "foodOrdersWaiting  ";
        name[17] = (char)(i/10+48);
        name[18] = (char)(i%10+48);
        foodOrdersWaiting[i] = CreateMV(name,-1);
        name = "coachAttendantFoodLineLength  ";
        name[28] = (char)(i/10+48);
        name[29] = (char)(i%10+48);
        coachAttendantFoodLineLength[i] = CreateMV(name,-1);

        name = "coachAttendantOrderHolder  ";
        name[25] = (char)(i/10+48);
        name[26] = (char)(i%10+48);
        coachAttendantOrderHolder[i] = CreateMV(name,-1);
        name = "coachAttendantOrderFoodOrder  ";
        name[28] = (char)(i/10+48);
        name[29] = (char)(i%10+48);
        coachAttendantOrderFoodOrder[i] = CreateMV(name,-1);
        name = "coachAttendantOrderValidFoodOrder  ";
        name[33] = (char)(i/10+48);
        name[34] = (char)(i%10+48);
        coachAttendantOrderValidFoodOrder[i] = CreateMV(name,-1);
    }
    nextSeat = CreateMV("nextSeat",-1);
    /*--end CoachAttendant/Passenger interactions*/

    /*data for Porter/Passenger interactions*/
    for(i = 0; i < PORTERS; i++) {
        name = "porterBaggageLineLength  ";
        name[23] = (char)(i/10+48);
        name[24] = (char)(i%10+48);
        porterBaggageLineLength[i] = CreateMV(name,-1);
        name = "porterAvailable  ";
        name[15] = (char)(i/10+48);
        name[16] = (char)(i%10+48);
        porterAvailable[i] = CreateMV(name,-1);

        name = "passengerBaggage  ";
        name[16] = (char)(i/10+48);
        name[17] = (char)(i%10+48);
        passengerBaggage[i] = CreateMV(name,-1);

        name = "porterBeddingLineLength  ";
        name[23] = (char)(i/10+48);
        name[24] = (char)(i%10+48);
        porterBeddingLineLength[i] = CreateMV(name,-1);
        name = "porterFirstClassBeddingLineLength  ";
        name[33] = (char)(i/10+48);
        name[34] = (char)(i%10+48);
        porterFirstClassBeddingLineLength[i] = CreateMV(name,-1);

        name = "passengerBeddingHolder  ";
        name[22] = (char)(i/10+48);
        name[23] = (char)(i%10+48);
        passengerBeddingHolder[i] = CreateMV(name,-1);
        name = "passengerBeddingHasBedding  ";
        name[26] = (char)(i/10+48);
        name[27] = (char)(i%10+48);
        passengerBeddingHasBedding[i] = CreateMV(name,-1);
    }
    /*--end Porter/Passenger data*/

    /*data for Waiter/Passenger interactions*/
    for(i = 0; i < WAITERS; i++) {
        name = "waiterLineLength  ";
        name[16] = (char)(i/10+48);
        name[17] = (char)(i%10+48);
        waiterLineLength[i] = CreateMV(name,-1);

        name = "passengerFoodHolder  ";
        name[19] = (char)(i/10+48);
        name[20] = (char)(i%10+48);
        passengerFoodHolder[i] = CreateMV(name,-1);
        name = "passengerFoodFoodOrder  ";
        name[22] = (char)(i/10+48);
        name[23] = (char)(i%10+48);
        passengerFoodFoodOrder[i] = CreateMV(name,-1);
        name = "passengerFoodValidFoodOrder  ";
        name[27] = (char)(i/10+48);
        name[28] = (char)(i%10+48);
        passengerFoodValidFoodOrder[i] = CreateMV(name,-1);
    }
    /*--end Waiter/Passenger data*/

    /*data for ticketChecker/Conductor interactions*/
    ticketCheckerWaiting = CreateMV("ticketCheckerWaiting",-1);
    conductorWaiting = CreateMV("conductorWaiting",-1);
    /*--end ticketChecker/Conductor data*/

    /*data for Conductor/CoachAttendant interactions*/
    for(i = 0; i < MAX_STOPS; i++) {
        name = "passengersBoardedAtThisStop  ";
        name[27] = (char)(i/10+48);
        name[28] = (char)(i%10+48);
        passengersBoardedAtThisStop[i] = CreateMV(name,-1);
    }
    /*--end conductor/CA interactions*/

    /*data for steward/passenger interations*/
    stewardLineLength = CreateMV("stewardLineLength",-1);
    stewardAvailable = CreateMV("stewardAvailable",-1);

    stewardTicketToCheckHolder = CreateMV("stewardTicketToCheckHolder",-1);
    stewardTicketToCheckWaiter = CreateMV("stewardTicketToCheckWaiter",-1);
    /*--end steward/passenger data*/

    /*data for steward/waiter interactions*/
    for(i = 0; i < WAITERS; i++) {
        name = "waiterOnBreak  ";
        name[13] = (char)(i/10+48);
        name[14] = (char)(i%10+48);
        waiterOnBreak[i] = CreateMV(name,-1);
    }
    /*--end steward/waiter data*/

    /*data for chef/ANYONE interactions*/
    for(i = 0; i < CHEFS; i++) {
        name = "chefOnBreak  ";
        name[11] = (char)(i/10+48);
        name[12] = (char)(i%10+48);
        chefOnBreak[i] = CreateMV(name,-1);
        name = "chefFirstClassOrdersLeft  ";
        name[24] = (char)(i/10+48);
        name[25] = (char)(i%10+48);
        chefFirstClassOrdersLeft[i] = CreateMV(name,-1);
        name = "chefRegularOrdersLeft  ";
        name[21] = (char)(i/10+48);
        name[22] = (char)(i%10+48);
        chefRegularOrdersLeft[i] = CreateMV(name,-1);
    }
    /*--end chef/ANYONE shared data*/


    /**************************************/
    /* Locks, etc			      */
    /**************************************/

    IDLock = CreateServerLock("IDLock",-1);
    atAStopLock = CreateServerLock("atAStopLock",-1);
    getOffAtThisStopLock = CreateServerLock("getOffAtThisStopLock",-1);
    getOffAtThisStop = CreateServerCondition("getOffAtThisStopCV",-1);
    ticketRevenueLock = CreateServerLock("ticketRevenueLock",-1);
    diningCarRevenueLock = CreateServerLock("diningCarRevenueLock",-1);
    waiterRevenueLock = CreateServerLock("waiterRevenueLock",-1);
    ticketLock = CreateServerLock("ticketLock",-1);
    ticketCheck = CreateServerCondition("ticketCheck",-1);
    globalSeatLock = CreateServerLock("globalSeatLock",-1);
    globalFoodLock = CreateServerLock("globalFoodLock",-1);
    waitingForBoardingCompletionLock = CreateServerLock("waitingForBoardingCompletionLock",-1);
    waitingForBoardingCompletion = CreateServerCondition("WaitingForBoardingCompletionCV",-1);
    boardingPassengersCountLock = CreateServerLock("BoardingPassengersCountLock",-1);
    stewardLock = CreateServerLock("stewardLock",-1);
    steward = CreateServerCondition("stewardCV",-1);
    diningCarCapacityLock = CreateServerLock("diningCarCapacityLock",-1);
    stewardGiveWaiterLock = CreateServerLock("stewardGiveWaiterLock",-1);
    stewardGiveWaiter = CreateServerCondition("stewardGiveWaiterCV",-1);
    stewardLine = CreateServerCondition("stewardLineCV",-1);
    finalConfirmation = CreateServerCondition("finalConfirmationCV",-1);

    /*setup bullhockey*/

    for(i=0; i<MAX_STOPS; i += 1) {
        name = "waitingForTrainCV  ";
        name[17] = (char)(i/10+48);
        name[18] = (char)(i%10+48);
        waitingForTrain[i] = CreateServerCondition(name,-1);
        name = "waitingForTrainLock  ";
        name[19] = (char)(i/10+48);
        name[20] = (char)(i%10+48);
        waitingForTrainLock[i] = CreateServerLock(name,-1);
    }

    ticketChecker = CreateServerCondition("ticketChecker",-1);
    ticketCheckerLine = CreateServerCondition("ticketCheckerLine",-1);
    ticketCheckerLock = CreateServerLock("ticketCheckerLock",-1);
    passengerCountLock = CreateServerLock("passengerCountLock",-1);

    waitingForGo = CreateServerCondition("waitingForGoCV",-1);
    waitingForGoLock = CreateServerLock("waitingForGoLock",-1);
    waitingForStop = CreateServerCondition("waitingForStopCV",-1);
    waitingForStopLock = CreateServerLock("waitingForStopLock",-1);

    for(i=0; i<COACH_ATTENDANTS; i += 1) {
        name = "coachAttendantCV  ";
        name[16] = (char)(i/10+48);
        name[17] = (char)(i%10+48);
        coachAttendant[i] = CreateServerCondition(name,-1);
        name = "coachAttendantFirstLineCV  ";
        name[25] = (char)(i/10+48);
        name[26] = (char)(i%10+48);
        coachAttendantFirstLine[i] = CreateServerCondition(name,-1);
        name = "coachAttendantRegularLineCV  ";
        name[27] = (char)(i/10+48);
        name[28] = (char)(i%10+48);
        coachAttendantRegularLine[i] = CreateServerCondition(name,-1);
        name = "coachAttendantLineCV  ";
        name[20] = (char)(i/10+48);
        name[21] = (char)(i%10+48);
        coachAttendantLine[i] = CreateServerCondition(name,-1);
        name = "coachAttendantLock  ";
        name[18] = (char)(i/10+48);
        name[19] = (char)(i%10+48);
        coachAttendantLock[i] = CreateServerLock(name,-1);
        name = "coachAttendantLineLock  ";
        name[22] = (char)(i/10+48);
        name[23] = (char)(i%10+48);
        coachAttendantLineLock[i] = CreateServerLock(name,-1);
        name = "getSeatLock  ";
        name[11] = (char)(i/10+48);
        name[12] = (char)(i%10+48);
        getSeatLock[i] = CreateServerLock(name,-1);
        name = "getSeat  ";
        name[7] = (char)(i/10+48);
        name[8] = (char)(i%10+48);
        getSeat[i] = CreateServerCondition(name,-1);
        name = "CAWaitingForPorterCV  ";
        name[20] = (char)(i/10+48);
        name[21] = (char)(i%10+48);
        CAWaitingForPorter[i] = CreateServerCondition(name,-1);
        name = "CAWaitingForPorterLock  ";
        name[22] = (char)(i/10+48);
        name[23] = (char)(i%10+48);
        CAWaitingForPorterLock[i] = CreateServerLock(name,-1);
        name = "coachAttendantGetFoodCV  ";
        name[23] = (char)(i/10+48);
        name[24] = (char)(i%10+48);
        coachAttendantGetFood[i] = CreateServerCondition(name,-1);
        name = "coachAttendantGetFoodLock  ";
        name[25] = (char)(i/10+48);
        name[26] = (char)(i%10+48);
        coachAttendantGetFoodLock[i] = CreateServerLock(name,-1);
        name = "coachAttendantFoodLineCV  ";
        name[24] = (char)(i/10+48);
        name[25] = (char)(i%10+48);
        coachAttendantFoodLine[i] = CreateServerCondition(name,-1);
    }

    for(i=0; i<PORTERS; i += 1) {
        name = "porterCV  ";
        name[8] = (char)(i/10+48);
        name[9] = (char)(i%10+48);
        porter[i] = CreateServerCondition(name,-1);
        name = "porterBaggageLineCV  ";
        name[19] = (char)(i/10+48);
        name[20] = (char)(i%10+48);
        porterBaggageLine[i] = CreateServerCondition(name,-1);
        name = "porterLineCV  ";
        name[12] = (char)(i/10+48);
        name[13] = (char)(i%10+48);
        porterLine[i] = CreateServerCondition(name,-1);
        name = "porterLock  ";
        name[10] = (char)(i/10+48);
        name[11] = (char)(i%10+48);
        porterLock[i] = CreateServerLock(name,-1);
        name = "porterBaggageLineLock  ";
        name[21] = (char)(i/10+48);
        name[22] = (char)(i%10+48);
        porterBaggageLineLock[i] = CreateServerLock(name,-1);
        name = "porterBeddingLineCV  ";
        name[19] = (char)(i/10+48);
        name[20] = (char)(i%10+48);
        porterBeddingLine[i] = CreateServerCondition(name,-1);
        name = "porterFirstClassBeddingLineCV  ";
        name[29] = (char)(i/10+48);
        name[30] = (char)(i%10+48);
        porterFirstClassBeddingLine[i] = CreateServerCondition(name,-1);
        name = "porterBeddingLineLock  ";
        name[21] = (char)(i/10+48);
        name[22] = (char)(i%10+48);
        porterBeddingLineLock[i] = CreateServerLock(name,-1);
    }


    for(i = 0; i < WAITERS; i += 1) {
        name = "waiterLock  ";
        name[10] = (char)(i/10+48);
        name[11] = (char)(i%10+48);
        waiterLock[i] = CreateServerLock(name,-1);
        name = "waiterCV  ";
        name[8] = (char)(i/10+48);
        name[9] = (char)(i%10+48);
        waiter[i] = CreateServerCondition(name,-1);
        name = "waiterLineLock  ";
        name[14] = (char)(i/10+48);
        name[15] = (char)(i%10+48);
        waiterLineLock[i] = CreateServerLock(name,-1);
        name = "waiterLineCV  ";
        name[12] = (char)(i/10+48);
        name[13] = (char)(i%10+48);
        waiterLine[i] = CreateServerCondition(name,-1);
        name = "getFoodLock  ";
        name[11] = (char)(i/10+48);
        name[12] = (char)(i%10+48);
        waiterGetFoodLock[i] = CreateServerLock(name,-1);
        name = "getFoodCV  ";
        name[9] = (char)(i/10+48);
        name[10] = (char)(i%10+48);
        waiterGetFood[i] = CreateServerCondition(name,-1);
    }

    for(i=0; i<CHEFS; i += 1) {
        name = "chefLock  ";
        name[8] = (char)(i/10+48);
        name[9] = (char)(i%10+48);
        chefLock[i] = CreateServerLock(name,-1);
        name = "chefCV  ";
        name[6] = (char)(i/10+48);
        name[7] = (char)(i%10+48);
        chef[i] = CreateServerCondition(name,-1);
        name = "chefOrdersLineCV  ";
        name[16] = (char)(i/10+48);
        name[17] = (char)(i%10+48);
        chefRegularOrdersLine[i] = CreateServerCondition(name,-1);
        name = "chefFirstClassOrdersLineCV  ";
        name[26] = (char)(i/10+48);
        name[27] = (char)(i%10+48);
        chefFirstClassOrdersLine[i] = CreateServerCondition(name,-1);
        name = "chefOrdersLineLock  ";
        name[18] = (char)(i/10+48);
        name[19] = (char)(i%10+48);
        chefOrdersLineLock[i] = CreateServerLock(name,-1);
    }
}
コード例 #22
0
int main()
{
	int lockStatus, cvStatus, mvStatus, waitStatus;

	WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1);

	lockStatus = CreateLock("lock1",5);
	if(lockStatus == -1)
	{
		WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nLock Created by the server\n\0", -1 , -1, -1);
	}


	cvStatus = CreateCV("cv1",3);
	if(cvStatus == -1)
	{
		WriteToConsole("\nError Occurred while creating CV. Exiting program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nCV Created by the server\n\0", -1 , -1, -1);
	}


	mvStatus = CreateMV("mv1", 3, 1);
	if(mvStatus == -1)
	{
		WriteToConsole("\nError Occurred while creating MV. Exiting program\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nMV Created by the server\n\0", -1 , -1, -1);
	}


	WriteToConsole("\nAcquiring Lock\n",-1,-1,-1);
	lockStatus = Acquire("lock1",5);
	if(lockStatus == -1)
	{
		WriteToConsole("\nFailed to Acquire Lock. Exiting Program\0n", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nAcquired Lock\n\0", -1, -1, -1);
	}

	WriteToConsole("\nSetting MV1 to 100.\n",-1,-1,-1);
	SetMV("mv1", 3, 0, 100);

	WriteToConsole("\nWaiting on the condition cv1 with lock1.\n",-1,-1,-1);
	waitStatus = Wait("cv1",3,"lock1",5);
	if(lockStatus == -1)
	{
		WriteToConsole("\nServer failed to wait. Exiting program.\n\0", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nClient 1 is waiting. Start client 2 to signal.\0n", -1, -1, -1);
	}

	WriteToConsole("\nGot signal from client 2.\n\0", -1, -1, -1);

	WriteToConsole("\nReleasing Lock\n\0", -1, -1, -1);
	lockStatus = Release("lock1",5);
	if(lockStatus == -1)
	{
		WriteToConsole("\nFailed to Release Lock. Exiting Program\0n", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nReleased Lock\n\0", -1, -1, -1);
	}

	WriteToConsole("\nDeleting Lock\n\0", -1, -1, -1);
	lockStatus = DeleteLock("lock1",5);
	if(lockStatus == -1)
	{
		WriteToConsole("\nFailed to Delete Lock. Exiting Program\0n", -1, -1, -1);
		Exit(0);
	}
	else
	{
		WriteToConsole("\nDeleted Lock\n\0", -1, -1, -1);
	}

	Exit(0);
}
コード例 #23
0
ファイル: appClerk.c プロジェクト: meldefon/OSsome
void initialize(struct Monitor *m, int clerkType_, int size) {
	int i;
	char* lockName;
	int nameLength;

	nameLength = 50;

	if(clerkType_ == 0) {
		m->lineLock = CreateLock("lineLock0", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock0", 15);
		m->newClerkId = CreateMV("newClerkId0", 11, 1);
		m->clerkType = CreateMV("clerkType0", 10, 1);
		m->lineCV = CreateMV("lineCV0", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV0", 12, size);
		m->senLineCV = CreateMV("senLineCV0", 10, size);
		m->limboLineCV = CreateMV("limboLineCV0", 12, size);
		m->clerkLock = CreateMV("clerkLock0", 10, size);
		m->clerkCV = CreateMV("clerkCV0", 8, size);
		m->breakCV = CreateCondition("breakCV0", 8);
		m->lineCount = CreateMV("lineCount0", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount0", 15, size);
		m->senLineCount = CreateMV("senLineCount0", 13, size);
		m->clerkState = CreateMV("clerkState0", 11, size);
		m->numOfClerks = CreateMV("numOfClerks0", 12, 1);
		m->cashReceived = CreateMV("cashReceived0", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer0", 17, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo0", 20, 1);
		lockName = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\0";
	} else if(clerkType_ == 1) {
		m->lineLock = CreateLock("lineLock1", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock1", 15);
		m->newClerkId = CreateMV("newClerkId1", 11, 1);
		m->clerkType = CreateMV("clerkType1", 10, 1);
		m->lineCV = CreateMV("lineCV1", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV1", 12, size);
		m->senLineCV = CreateMV("senLineCV1", 10, size);
		m->limboLineCV = CreateMV("limboLineCV0", 12, size);
		m->clerkLock = CreateMV("clerkLock1", 10, size);
		m->clerkCV = CreateMV("clerkCV1", 8, size);
		m->breakCV = CreateCondition("breakCV1", 8);
		m->lineCount = CreateMV("lineCount1", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount1", 15, size);
		m->senLineCount = CreateMV("senLineCount1", 13, size);
		m->clerkState = CreateMV("clerkState1", 11, size);
		m->numOfClerks = CreateMV("numOfClerks1", 12, 1);
		m->cashReceived = CreateMV("cashReceived1", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer1", 16, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo1", 20, 1);
		lockName = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\0";
	} else if(clerkType_ == 2) {
		m->lineLock = CreateLock("lineLock2", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock2", 15);
		m->newClerkId = CreateMV("newClerkId2", 11, 1);
		m->clerkType = CreateMV("clerkType2", 10, 1);
		m->lineCV = CreateMV("lineCV2", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV2", 12, size);
		m->senLineCV = CreateMV("senLineCV2", 10, size);
		m->limboLineCV = CreateMV("limboLineCV2", 12, size);
		m->clerkLock = CreateMV("clerkLock2", 10, size);
		m->clerkCV = CreateMV("clerkCV2", 8, size);
		m->breakCV = CreateCondition("breakCV2", 8);
		m->lineCount = CreateMV("lineCount2", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount2", 15, size);
		m->senLineCount = CreateMV("senLineCount2", 13, size);
		m->clerkState = CreateMV("clerkState2", 11, size);
		m->numOfClerks = CreateMV("numOfClerks2", 12, 1);
		m->cashReceived = CreateMV("cashReceived2", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer2", 16, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo2", 20, 1);
		lockName = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\0";
	} else if(clerkType_ == 3) {
		m->lineLock = CreateLock("lineLock3", 9);
		m->newClerkIdLock = CreateLock("newClerkIdLock3", 15);
		m->newClerkId = CreateMV("newClerkId3", 11, 1);
		m->clerkType = CreateMV("clerkType3", 10, 1);
		m->lineCV = CreateMV("lineCV3", 7, size);
		m->bribeLineCV = CreateMV("bribeLineCV3", 12, size);
		m->senLineCV = CreateMV("senLineCV3", 10, size);
		m->limboLineCV = CreateMV("limboLineCV3", 12, size);
		m->clerkLock = CreateMV("clerkLock3", 10, size);
		m->clerkCV = CreateMV("clerkCV3", 8, size);
		m->breakCV = CreateCondition("breakCV3", 8);
		m->lineCount = CreateMV("lineCount3", 10, size);
		m->bribeLineCount = CreateMV("bribeLineCount3", 15, size);
		m->senLineCount = CreateMV("senLineCount3", 13, size);
		m->clerkState = CreateMV("clerkState3", 11, size);
		m->numOfClerks = CreateMV("numOfClerks3", 12, 1);
		m->cashReceived = CreateMV("cashReceived3", 13, 1);
		m->currentCustomer = CreateMV("currentCustomer3", 16, size);
		m->numCustomersInLimbo = CreateMV("numCustomersInLimbo3", 20, 1);
		lockName = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\0";
	}

}
コード例 #24
0
ファイル: customer-d.c プロジェクト: shadowwalk/OSNachos
void main()
{
	
	/* Print_Stmt("Calling start simulation\n"); */
	StartSimulation();
	/* Print_Stmt("Back from start simulation\n"); */
		
	/* -----------------INITIALISATION -----------------------*/
		
	/* ------------------FOOD TO BE COOKED AND FOOD READY STRUCTURE ATTRIBUTES MONITOR VARIABLES CREATION------------------- */
	
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/*						INITIALISATION BLOCK BEGINS				   */
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/* --------EVERY ENTITY DOES EVERYTHING BELOW--------------------- */
	/* --------------------------------------------------------------- */

	
	
	/*------------------------------------------------------------	*/
	/* 				CREATE all the Locks using Syscalls				*/
	/*------------------------------------------------------------	*/
	custLineLock = CreateLock("custLineLk", 10, 0);
	foodReadyDBLock = CreateLock("foodReadyDBLk", 13, 0);
	foodToBeCookedDBLock = CreateLock("fd2BCokdDBLk", 12, 0);
	nextTokenNumberLock = CreateLock("nextTokenNoLk", 13, 0);
	moneyAtRestaurantLock = CreateLock("moneyAtRestLk", 13, 0);
	waitToGoLock = CreateLock("waitToGoLk", 10, 0);
	tablesDataLock = CreateLock("tablesDataLk", 12, 0);
	eatInWaitingLock = CreateLock("eatInWaitingLk", 14, 0);
	eatInFoodWaitingLock = CreateLock("eatInFWLk", 9, 0);
	foodToBagLock = CreateLock("foodToBagLk", 11, 0);
	foodBaggedListLock = CreateLock("foodBgdListLk", 13, 0);
	inventoryLock = CreateLock("inventoryLk", 11, 0);
	managerLock = CreateLock("managerLk", 9, 0);
	whatToCookNextLock = CreateLock("whatToCookNextLk", 16, 0);
	stopSixBurgerLock = CreateLock("stop6BLk", 8, 0);
	stopThreeBurgerLock = CreateLock("stop3BLk", 8, 0);
	stopVegBurgerLock = CreateLock("stopVBLk", 8, 0);
	stopFriesLock = CreateLock("stopFLk", 7, 0);
	waiterSleepLock = CreateLock("waiterSleepLk", 13, 0);
	customerDataLock = CreateLock("custDataLk", 10, 0);
	wakeUpCookLock = CreateLock("wakeUpCookLk", 12, 0);
	custServedLock = CreateLock("custServedLk", 12, 0);
	nextWaiterIndexLock = CreateLock("nxtWtrIdxLk", 11, 0);
	nextCookIndexLock = CreateLock("nxtCkIdxLk", 10, 0);
	nextCustomerIndexLock = CreateLock("nxtCustIdxLk", 12, 0);
	nextOrderTakerIndexLock = CreateLock("nxtOTIdxLk", 10, 0);
	whatToCookFirstLock = CreateLock("what2CkFrstLk", 13, 0); 
	cooksOnBreakCountLock = CreateLock("cksOnBrkCntLk", 13, 0);
	workingCookLock = CreateLock("workingCooklk", 13, 0);
	BagTheOrdersLock	= CreateLock("BagTheOrdersLk", 14, 0);	
	
	/* Create OT_COUNT number of locks, one Lock for each Ordertaker	*/
	for(index = 1; index <= OT_COUNT; index++)
		orderTakerLock[index] = CreateLock("orderTakerLk", 12, index);
	
	/* --------------------------------------------------------------- */
	
	
	
/* 	Print_Stmt("after creating locks\n"); */
	
	/*------------------------------------------------------------	*/
	/* Create all the Condition variables using Syscalls			*/
	/*------------------------------------------------------------	*/
	custLineCV = CreateCV("custLineCV", 10, 0);
	tablesDataCV = CreateCV("tablesDataCV", 12, 0); 
	eatInWaitingCV = CreateCV("eatInWaitingCV", 14, 0);
	eatInFoodWaitingCV = CreateCV("eatInFWtngCV", 12, 0);
	managerCV = CreateCV("managerCV", 9, 0);
	waiterSleepCV = CreateCV("waiterSleepCV", 13, 0);
	wakeUpCookCV = CreateCV("wakeUpCookCV", 12, 0);
	toGoCV = CreateCV("toGoCV", 6, 0); 
	/* Create OT_COUNT number of Cvs, one CV for each Ordertaker	*/
	for(index = 1; index <= OT_COUNT; index++)
		orderTakerCV[index] = CreateCV("orderTakerCV", 12, index);
		
	/* --------------------------------------------------------------- */
	
	
	/* foodReadyData.sixBurger */
	readySixBurgerMVi = CreateMV("ready6B", 7, 100, 0);
	
	/* foodReadyData.threeeBurger */
	readyThreeBurgerMVi = CreateMV("ready3B", 7, 100, 0);
	
	/* foodReadyData.vegBurger */
	readyVegBurgerMVi = CreateMV("ready6VB", 8, 100, 0);
	
	/* foodReadyData.fries */
	readyFriesMVi = CreateMV("readyF", 6, 100, 0);

	/* foodToBeCookedData.sixBurger */
	toBeCookedSixburgerMVi = CreateMV("toBecooked6B", 12, 0, 0);
	
	/* foodToBeCookedData.threeBurger */
	toBeCookedThreeburgerMVi = CreateMV("toBecooked3B", 12, 0, 0);
	
	/* foodToBeCookedData.vegBurger */
	toBeCookedVegburgerMVi = CreateMV("toBecookedVB", 12, 0, 0);
	
	/* foodToBeCookedData.fries */
	toBeCookedFriesMVi = CreateMV("toBecookedF", 11, 0, 0); 
	
	/*--------------------------------------------------------------------------------------------- */
	
	
	
	
	
	
	/* -------- FILL IN THE CUST DATABASE WITH DEFAULT VALUES--------------------------------------- */
	
	for(index = 1; index <= CUST_COUNT; index++)
	{
		/* custData[index].bagged */
		baggedincustDBMVi[index] = CreateMV("baggedMV", 8, 0, index);
		
		/* custData[index].dineType */
		dineTypeincustDBMVi[index] = CreateMV("dineTypeMV", 10, 0, index);
		
		/* custData[index].delivered */
		deliveredincustDBMVi[index] = CreateMV("deliveredMV", 11, 0, index);
		
		/* baggedlist[index] */
		baggedListMVi[index] = CreateMV("baggedMV", 8, 0, index);
		
		/* custData[index].myOT - initially myOT is -1 */
		myOTMVi[index] = CreateMV("myOTMV", 6, -1, index);
		
		/* custData[index].ordered */
		orderedincustDBMVi[index] = CreateMV("orderedMV", 9, 0, index);
		
		/* custData[index].sixBurger/threeBurger/etc. */
		sixBurgerincustDBMVi[index] = CreateMV("sixBurgerMV", 11, 0, index);
		
		threeBurgerincustDBMVi[index] = CreateMV("threeBurgerMV", 13, 0, index);
		
		vegBurgerincustDBMVi[index] = CreateMV("vegBurgerMV", 11, 0, index);
		
		friesincustDBMVi[index] = CreateMV("friesMV", 7, 0, index);
		
		sodaincustDBMVi[index] = CreateMV("sodaMV", 6, 0, index);
		
		/* custData[Index].tokenNo/tableNo */
		tokenNoincustDBMVi[index] = CreateMV("tokenNoMV", 9, 0, index);
		
		tableNoincustDBMVi[index] = CreateMV("tableNoMV", 9, -1, index);
	}
	/* -------------------------------------------------------------------------------- */
	
	
	
	
	
	/* ---------------------  CREATE ALL THE GLOBAL MONITOR VARIABLES ----------------- */
	
	nextOrderTakerIndexMVi = CreateMV("nextOTIndex", 11, 1, 0);
	custServedMVi = CreateMV("custServed", 10, 0, 0);
	foodToBagMVi = CreateMV("foodToBag", 9, 0, 0);
	nextCustomerIndexMVi = CreateMV("nextCustIndex", 13, 1, 0);
	custLineLengthMVi = CreateMV("custLineLength", 14, 0, 0);
	managerLineLengthMVi = CreateMV("mgrLineLength", 13, 0, 0);
	tableAvailableMVi = CreateMV("tableAvailable", 14, 0, 0);
	nextTokenNumberMVi = CreateMV("nextTokenNo", 11, 0, 0);
	moneyAtRestaurantMVi = CreateMV("moneyAtRest", 11, 0, 0);
	RefillcashMVi = CreateMV("Refillcash", 10, 0, 0);
	broadcastedTokenNoMVi = CreateMV("bcastTokenNo", 12, 0, 0);
	inventoryMVi = CreateMV("inventory", 9, 100, 0);
	whatToCookNextMVi = CreateMV("whatToCookNext", 14, 0, 0);									
	stopSixBurgerMVi = CreateMV("stop6B", 6, 1, 0);
	stopThreeBurgerMVi = CreateMV("stop3B", 6, 1, 0);
	stopVegBurgerMVi = CreateMV("stopVB", 6, 1, 0);
	stopFriesMVi = CreateMV("stopF", 5, 1, 0);
	
	/* tables[index] */
	for(index = 0; index < TABLE_COUNT; index++)
	{ 	
		tablesMVi[index] = CreateMV("tablesMV", 8, 0, index);
	}
	
	for(index = 1; index <= OT_COUNT; index++)
	{
		
		orderTakerStatusMVi[index] = CreateMV("OTstatusMV", 10, OT_BUSY, index);
		
	}
/* 	
	for(index = 1; index <= 4; index++)
	{
		switch(index) 
		{
			case 1:
					workingCooksMVi[index] = CreateMV("wkingCks6$", 9, 0, index);
					break;
			case 2:
					workingCooksMVi[index] = CreateMV("wkingCks3$", 9, 0, index);
					break;		
			case 3:
					workingCooksMVi[index] = CreateMV("wkingCksV$", 9, 0, index);
					break;
			case 4:
					workingCooksMVi[index] = CreateMV("wkingCksF$", 9, 0, index);
					break;
		}
	} */
	
/* 	for(index = 1; index <= CUST_COUNT; index++)
	{

		SetMV(baggedincustDBMVi[index], 0);
		SetMV(deliveredincustDBMVi[index], 0);
		SetMV(baggedListMVi[index],0);
		SetMV(myOTMVi[index],0);
		SetMV(orderedincustDBMVi[index],0);
		SetMV(tokenNoincustDBMVi[index],-1);
		SetMV(tableNoincustDBMVi[index],-1); 
		if (index%2 == 0)
			tempV = 1;
		else
			tempV = 0;
			SetMV(dineTypeincustDBMVi[index],tempV);	
			SetMV(friesincustDBMVi[index],tempV);		
			SetMV(threeBurgerincustDBMVi[index],tempV);
				if (index%2 == 0)
			tempV = 0;
		else
			tempV = 1;
			SetMV(vegBurgerincustDBMVi[index],tempV);
			SetMV(sixBurgerincustDBMVi[index],tempV);		
			SetMV(sodaincustDBMVi[index],tempV);

	} */
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/*						INITIALISATION BLOCK END				   */
	/* --------------------------------------------------------------- */
	/* --------------------------------------------------------------- */
	/* --------EVERY ENTITY DOES EVERYTHING ABOVE--------------------- */
	/* --------------------------------------------------------------- */
	/* -----------------INITIALISATION END-----------------------*/
	Print_Stmt("Cust INITIALISATION END\n");

	Customer(); 

	/* ------------------------------------------------------------------------------ */

}
コード例 #25
0
int
main()
{
    int lockStatus, cvStatus, mvStatus, mvId, mvValue;

    WriteToConsole("\nCreating a Lock\n\0", -1, -1, -1);

    lockStatus = CreateLock("lock1",5);
    if(lockStatus == -1)
    {
        WriteToConsole("\nError Occurred while creating Lock. Exiting program\n\0", -1, -1, -1);
        Exit(0);
    }
    else
    {
        WriteToConsole("\nLock Created by the server.\n\0", -1, -1, -1);
    }


    WriteToConsole("\nCreating a MV\n\0", -1, -1, -1);

    mvStatus = CreateMV("mv1",3, 5);
    if(mvStatus == -1)
    {
        WriteToConsole("\nError Occurred while creating MV. Exiting program\n\0", -1, -1, -1);
        Exit(0);
    }
    else
    {
        WriteToConsole("\nMV Created by the server.\n\0", -1, -1, -1);
    }


    WriteToConsole("\nAcquiring lock to access Monitor Variable\n\0", -1, -1, -1);

    lockStatus = Acquire("lock1",5);
    if(lockStatus == -1)
    {
        WriteToConsole("\nError Occurred while acquiring Lock. Exiting program\n\0", -1, -1, -1);
        Exit(0);
    }
    else
    {
        WriteToConsole("\nLock acquired by the server.\n\0", -1, -1, -1);
    }

    WriteToConsole("\nSetting MV to 100\n", -1, -1, -1);
    mvStatus = SetMV("mv1",3, 1, 100);
    if(mvStatus == -1)
    {
        WriteToConsole("\nFailed to Set MV. Exiting Program\n\0", -1, -1, -1);
        Exit(0);
    }
    else
    {
        WriteToConsole("\nMV set successfully.\n\0", -1, -1, -1);
    }


    WriteToConsole("\nTrying to fetch value at invalid mv Index : %d\n\0", 21, -1,-1);
    mvValue = GetMV("mv1",3, 20);
    if(mvValue == -1)
    {
        WriteToConsole("\nInvalid mvIndex, Failed to fetch value at given index. Exiting Program\n\0", -1, -1, -1);
        Exit(0);
    }
    else
    {
        WriteToConsole("\nAbnormal Execution\n\0", -1, -1, -1);
    }

    Exit(0);
}
コード例 #26
0
int main() {
	/* ------------------Local data -------------------------*/
	int myIndex;

	int initIndex = CreateMV("AppIndex", sizeof("AppIndex"), 1, 0x9999);
	int initIndexLock = ServerCreateLock("AppIndexLock", sizeof("AppIndexLock"), 1);

	int mySSN;
	int i;
	int cType = 0;

	enum BOOLEAN loop = true;
	int shutdown = CreateMV("shutdown", sizeof("shutdown"), 1, 0x9999);
	/* -----------------Shared Data------------------------*/

	/* Number of customers/senators in office and thier locks */
	int officeSenator = CreateMV("officeSenator", sizeof("officeSenator"), 1, 0x9999);
	int officeCustomer = CreateMV("officeCustomer", sizeof("officeCustomer"), 1, 0x9999);	
	int senatorLock = ServerCreateLock("senatorLock", sizeof("senatorLock"), 1);
	int customerLock = ServerCreateLock("customerLock", sizeof("customerLock"), 1);

	/*Locks, conditions, and data used for waitinng */
	int clerkWaitLock = ServerCreateLock("clerkWaitLock", sizeof("clerkWaitLock"), 1);
	int clerkWaitCV = ServerCreateCV("clerkWaitCV", sizeof("clerkWaitCV"), 1);
	int numAppWait = CreateMV("numAppWait", sizeof("numAppWait"), 1, 0x9999);

	/* Reg and priv line lengths, line locks, and reg and priv line conditions. */
	int regACLineLength = CreateMV("regACLineLength", sizeof("regACLineLength"), 1, 0x9999);
	int privACLineLength = CreateMV("privACLineLength", sizeof("privACLineLength"), 1, 0x9999);
	int acpcLineLock = ServerCreateLock("acpcLineLock", sizeof("acpcLineLock"), 1);
	int regACLineCV = ServerCreateCV("regACLineCV", sizeof("regACLineCV"), 1);
	int privACLineCV = ServerCreateCV("privACLineCV", sizeof("privACLineCV"), 1);


	/* Individual clerk locks, conditions, data, data booleans, and states */
	int appLock = ServerCreateLock("appLock", sizeof("appLock"), NUM_CLERKS);
	int appCV = ServerCreateCV("appCV", sizeof("appCV"), NUM_CLERKS);

	int appState = CreateMV("appState", sizeof("appState"), NUM_CLERKS, 0x9999);
	int appData = CreateMV("appData", sizeof("appData"), NUM_CLERKS, 0x9999);

	/* Money data and locks for each clerk type */
	int appMoney = CreateMV("appMoney", sizeof("appMoney"), 1, 0x9999);
	int appMoneyLock = ServerCreateLock("appMoneyLock", sizeof("appMoneyLock"), 1);

	/* Individual customer's file state, type, and its lock */
	int fileLock = ServerCreateLock("fileLock", sizeof("fileLock"), NUM_CUSTOMERS + NUM_SENATORS);
	int fileState = CreateMV("fileState", sizeof("fileState"), NUM_CUSTOMERS + NUM_SENATORS, 0x9999);
	int fileType = CreateMV("fileType", sizeof("fileType"), NUM_CUSTOMERS + NUM_SENATORS, 0x9999);

	traceLock = ServerCreateLock("traceLock", sizeof("traceLock"), 1);
	
	/* initializes myIndex */
	ServerAcquire(initIndexLock, 0);
	myIndex = GetMV(initIndex, 0);
	SetMV(initIndex, 0, GetMV(initIndex, 0) + 1);
	ServerRelease(initIndexLock, 0);
	
	SetMV(appState, myIndex, 1);

	/* --------------------BEGIN APPCLERK STUFF----------------*/
	while(loop == true){
		if (GetMV(shutdown, 0) == 1) {
			ServerAcquire(traceLock, 0);
			ClerkTrace("App", myIndex, 0x00, 0, "Shutting down.\n"); 
			ServerRelease(traceLock, 0);
			Exit(0);
		}
		ServerAcquire(senatorLock, 0);
		ServerAcquire(customerLock, 0);
		if(GetMV(officeSenator, 0) > 0 && GetMV(officeCustomer, 0) > 0){
			ServerRelease(senatorLock, 0);
			ServerRelease(customerLock, 0);

			ServerAcquire(clerkWaitLock, 0);
			ServerWait(clerkWaitCV, 0, clerkWaitLock, 0);
			ServerRelease(clerkWaitLock, 0);
		}
		else{
			ServerRelease(senatorLock, 0);
			ServerRelease(customerLock, 0);
		}

		ServerAcquire(acpcLineLock, 0);
		
		/* Check for the privileged customer line first
		*  If there are privileged customers, do AppClerk tasks, then received $500
		*/
		if(GetMV(privACLineLength, 0) > 0){
			/*Trace("Checking privLine\n", 0x9999);*/
			SetMV(privACLineLength, 0, GetMV(privACLineLength, 0)-1);

			ServerAcquire(senatorLock, 0);
			SetMV(numAppWait, 0, GetMV(numAppWait, 0)+1);	/* shows customer that one clerk is waiting */
			ServerRelease(senatorLock, 0);

			ServerAcquire(appLock, myIndex);
			SetMV(appState, myIndex, 0);	/* 0 = AVAILABLE */
			ServerSignal(privACLineCV, 0, acpcLineLock, 0); /* Signals the next customer in priv line */
			ServerRelease(acpcLineLock, 0);
			/*Trace("Waiting privLine\n", 0x9999);*/
			ServerWait(appCV, myIndex, appLock, myIndex); /* Waits for the next customer */

			mySSN = GetMV(appData, myIndex);
			ServerAcquire(fileLock, mySSN);

			/* check the customer type */
			if(GetMV(fileType, mySSN) == 0){ /* 0 = CUSTOMER */
				cType = 0;
			}
			else{
				cType = 1;	/* 1 = SENATOR */
			}

			if(GetMV(fileState, mySSN) == 0){ /* 0 = NONE */
				SetMV(fileState, mySSN, 2); /* 2 = APPDONE */
				ServerRelease(fileLock, mySSN);
			}
			else if(GetMV(fileState, mySSN) == 1){ /* 1 = PICDONE */
				SetMV(fileState, mySSN, 3); /* 3 = APPPICDONE */
				ServerRelease(fileLock, mySSN);
			}
			else{
				ServerAcquire(traceLock, 0);
				ClerkTrace("App", myIndex, "Cust", mySSN,
					"ERROR:Customer doesn't have a picture application or no application. What are you doing here?\n");
				ServerRelease(traceLock, 0);
				ServerRelease(fileLock, mySSN);
			}

			for (i = 0; i < 20; i++){
				Yield();
			}

			ServerAcquire(traceLock, 0);
			if(cType == 0){
				ClerkTrace("App", myIndex, "Cust", mySSN, "Customer's app has been filed.\n");
			}
			else{
				ClerkTrace("App", myIndex, "Sen", mySSN, "Senator's app has been filed.\n");
			}
			ServerRelease(traceLock, 0);

			ServerAcquire(appMoneyLock, 0);
			SetMV(appMoney, 0, GetMV(appMoney, 0) + 500);

			ServerAcquire(traceLock, 0);
			if(cType == 0){
				ClerkTrace("App", myIndex, "Cust", mySSN, "Accepts $500 from Customer.\n");
			}
			else{
				ClerkTrace("App", myIndex, "Sen", mySSN, "Accepts $500 from Senator.\n");
			}
			ServerRelease(traceLock, 0);

			ServerRelease(appMoneyLock, 0);
			ServerSignal(appCV, myIndex, appLock, myIndex); /* signal customer awake */
			ServerRelease(appLock, myIndex);	/* Release clerk lock */

		}	
		/* Check for regular customer line next.
		* If there are regular customers, do AppClerk tasks 
		*/
		else if(GetMV(regACLineLength,0) > 0){
			/*Trace("Checking regLine\n", 0x9999);*/
			SetMV(regACLineLength, 0, GetMV(regACLineLength, 0)-1);

			ServerAcquire(senatorLock, 0);
			SetMV(numAppWait, 0, GetMV(numAppWait, 0)+1);	/* shows customer that one clerk is waiting */
			ServerRelease(senatorLock, 0);

			ServerAcquire(appLock, myIndex);
			SetMV(appState, myIndex, 0); /* 0 = AVAILABLE */
			ServerSignal(regACLineCV, 0, acpcLineLock, 0); /* Signals the next customer in priv line */
			ServerRelease(acpcLineLock, 0);
			/*Trace("Waiting regLine\n", 0x9999);*/
			ServerWait(appCV, myIndex, appLock, myIndex); /* Waits for the next customer */

			mySSN = GetMV(appData, myIndex);
			ServerAcquire(fileLock, mySSN);

			/* check the customer type */
			if(GetMV(fileType, mySSN) == 0){
				cType = 0;
			}
			else{
				cType = 1;
			}

			if(GetMV(fileState, mySSN) == 0){ /* 0 = NONE */
				SetMV(fileState, mySSN, 2); /* 2 = APPDONE */
				ServerRelease(fileLock, mySSN);
			}
			else if(GetMV(fileState, mySSN) == 1){ /* 1 = PICDONE */
				SetMV(fileState, mySSN, 3); /* 3 = APPPICDONE */
				ServerRelease(fileLock, mySSN);
			}
			else{
				ServerAcquire(traceLock, 0);
				ClerkTrace("App", myIndex, "Cust", mySSN,
					"ERROR:Customer doesn't have a picture application or no application. What are you doing here?\n");
				ServerRelease(traceLock, 0);
				ServerRelease(fileLock, mySSN);
			}

			for (i = 0; i < 20; i++){
				Yield();
			}

			ServerAcquire(traceLock, 0);
			if(cType == 0){
				ClerkTrace("App", myIndex, "Cust", mySSN, "Informs Customer their app has been filed.\n");
			}
			else{
				ClerkTrace("App", myIndex, "Sen", mySSN, "Informs Senator their app has been filed.\n");
			}
			ServerRelease(traceLock, 0);

			ServerSignal(appCV, myIndex, appLock, myIndex); /* signal customer awake */
			ServerRelease(appLock, myIndex);	/* Release clerk lock */
		}
		/* If there are neither privileged or regular customers, go on break */
		else{
			/*Trace("Going on break\n", 0x9999);*/
			ServerRelease(acpcLineLock, 0);
			ServerAcquire(appLock, myIndex);
			SetMV(appState, myIndex, 2); /* 2 = BREAK */
			
			ServerAcquire(traceLock, 0);
			ClerkTrace("App", myIndex, 0x00, 0, "Going on break.\n");
			ServerRelease(traceLock, 0);

			ServerWait(appCV, myIndex, appLock, myIndex);
			
			ServerAcquire(traceLock, 0);
			ClerkTrace("App", myIndex, 0x00, 0, "Returning from break.\n");
			ServerRelease(traceLock, 0);
			
			ServerRelease(appLock, myIndex);
		}
	}
}
コード例 #27
0
int main() {
	/* ------------------Local data -------------------------*/
	int myIndex;

	int initIndex = CreateMV("PicIndex", sizeof("PicIndex"), 1, 0x9999);
	int initIndexLock = ServerCreateLock("PicIndexLock", sizeof("PicIndexLock"), 1);

	int mySSN;
	int i;
	int cType = 0;

	enum BOOLEAN loop = true;
	int shutdown = CreateMV("shutdown", sizeof("shutdown"), 1, 0x9999);
	/* -----------------Shared Data------------------------*/

	/* Number of customers/senators in office and thier locks */
	int officeSenator = CreateMV("officeSenator", sizeof("officeSenator"), 1, 0x9999);
	int officeCustomer = CreateMV("officeCustomer", sizeof("officeCustomer"), 1, 0x9999);	
	int senatorLock = ServerCreateLock("senatorLock", sizeof("senatorLock"), 1);
	int customerLock = ServerCreateLock("customerLock", sizeof("customerLock"), 1);

	/*Locks, conditions, and data used for waitinng */
	int clerkWaitLock = ServerCreateLock("clerkWaitLock", sizeof("clerkWaitLock"), 1);
	int clerkWaitCV = ServerCreateCV("clerkWaitCV", sizeof("clerkWaitCV"), 1);
	int numPicWait = CreateMV("numPicWait", sizeof("numPicWait"), 1, 0x9999);

	/* Reg and priv line lengths, line locks, and reg and priv line conditions. */
	int regPCLineLength = CreateMV("regPCLineLength", sizeof("regPCLineLength"), 1, 0x9999);
	int privPCLineLength = CreateMV("privPCLineLength", sizeof("privPCLineLength"), 1, 0x9999);
	int acpcLineLock = ServerCreateLock("acpcLineLock", sizeof("acpcLineLock"), 1);
	int regPCLineCV = ServerCreateCV("regPCLineCV", sizeof("regPCLineCV"), 1);
	int privPCLineCV = ServerCreateCV("privPCLineCV", sizeof("privPCLineCV"), 1);


	/* Individual clerk locks, conditions, data, data booleans, and states */
	int picLock = ServerCreateLock("picLock", sizeof("picLock"), NUM_CLERKS);
	int picCV = ServerCreateCV("picCV", sizeof("picCV"), NUM_CLERKS);
	int picDataBool = CreateMV("picDataBool", sizeof("picDataBool"), NUM_CLERKS, 0x9999);
	int picState = CreateMV("picState", sizeof("picState"), NUM_CLERKS, 0x9999);
	int picData = CreateMV("picData", sizeof("picData"), NUM_CLERKS, 0x9999);

	/* Money data and locks for each clerk type */
	int picMoney = CreateMV("picMoney", sizeof("picMoney"), 1, 0x9999);
	int picMoneyLock = ServerCreateLock("picMoneyLock", sizeof("picMoneyLock"), 1);

	/* Individual customer's file state, type, and its lock */
	int fileLock = ServerCreateLock("fileLock", sizeof("fileLock"), NUM_CUSTOMERS + NUM_SENATORS);
	int fileState = CreateMV("fileState", sizeof("fileState"), NUM_CUSTOMERS + NUM_SENATORS, 0x9999);
	int fileType = CreateMV("fileType", sizeof("fileType"), NUM_CUSTOMERS + NUM_SENATORS, 0x9999);

	traceLock = ServerCreateLock("traceLock", sizeof("traceLock"), 1);
	
	/* initializes myIndex */
	ServerAcquire(initIndexLock, 0);
	myIndex = GetMV(initIndex, 0);
	SetMV(initIndex, 0, GetMV(initIndex, 0) + 1);
	ServerRelease(initIndexLock, 0);
	
	SetMV(picState, myIndex, 1);

	/* --------------------BEGIN PICCLERK STUFF----------------*/
	while(loop == true){
		if (GetMV(shutdown, 0) == 1) {
			ServerAcquire(traceLock, 0);
			ClerkTrace("Pic", myIndex, 0x00, 0, "Shutting down.\n");
			ServerRelease(traceLock, 0);
			Exit(0);
		}
		ServerAcquire(senatorLock, 0);
		ServerAcquire(customerLock, 0);
		if (GetMV(officeSenator, 0) > 0 && GetMV(officeCustomer, 0) > 0) {
			ServerRelease(senatorLock, 0);
			ServerRelease(customerLock, 0);
			
			ServerAcquire(clerkWaitLock, 0);
			ServerWait(clerkWaitCV, 0, clerkWaitLock, 0);
			ServerRelease(clerkWaitLock, 0);
		}
		else{
			ServerRelease(senatorLock, 0);
			ServerRelease(customerLock, 0);
		}

		ServerAcquire(acpcLineLock, 0);

		/* Check for the privileged customer line first
		* If there are privileged customers, do PicClerk tasks, then receive $500
		*/
		if(GetMV(privPCLineLength, 0) > 0){
			SetMV(privPCLineLength, 0, GetMV(privPCLineLength, 0)-1);
			
			ServerAcquire(senatorLock, 0);
			SetMV(numPicWait, 0, GetMV(numPicWait, 0)+1);		/* Shows customer that one clerk is waiting */
			ServerRelease(senatorLock, 0);

			ServerAcquire(picLock, myIndex);
			SetMV(picState, myIndex, 0); /* 0 = AVAILABLE */
			ServerSignal(privPCLineCV, 0, acpcLineLock, 0);
			ServerRelease(acpcLineLock, 0);
			
			ServerWait(picCV, myIndex, picLock, myIndex);	/* Waits for the next customer */

			mySSN = GetMV(picData, myIndex);
			/* check the customer type */
			ServerAcquire(fileLock, mySSN);
			if (GetMV(fileType, mySSN) == 0) { /* 0 = CUSTOMER */
				cType = 0;
			} else {
				cType = 1;	/* 1 = SENATOR */
			}

			if(GetMV(fileState, mySSN) == 0){	/* 0 = NONE */
				SetMV(fileState, mySSN, 1);/* 1 = PICDONE */
				ServerRelease(fileLock, mySSN);
			}
			else if(GetMV(fileState, mySSN) == 2 ){ /* 2 = APPDONE */
				SetMV(fileState, mySSN, 3); /* 3 = APPPICDONE */
				ServerRelease(fileLock, mySSN);
			}
			else{
				ServerAcquire(traceLock, 0);
				ClerkTrace("Pic", myIndex, "Cust", mySSN,
					"ERROR: Customer does not have either an application or no application. What are you doing here?\n");
				ServerRelease(traceLock, 0);
				ServerRelease(fileLock, mySSN);
			}

			ServerAcquire(traceLock, 0);
			if (cType == 0) {
				ClerkTrace("Pic", myIndex, "Cust", mySSN, "Takes picture of Customer.\n");
			} else {
				ClerkTrace("Pic", myIndex, "Sen", mySSN, "Takes picture of Senator.\n");
			}
			ServerRelease(traceLock, 0);

			/* yield to take picture
			* print statement: "Taking picture"
			* picCV->Signal then picCV->Wait to
			* show customer picture
			*/
			while(GetMV(picDataBool, myIndex) == 0){ /* 0 = false */
				for(i = 0; i < 4; i++){
					Yield();
				}
				ServerSignal(picCV, myIndex, picLock, myIndex);	
				ServerWait(picCV, myIndex, picLock, myIndex);	/* Shows the customer the picture */

				if(GetMV(picDataBool, myIndex) == 0){
					ServerAcquire(traceLock, 0);
					if (cType == 0) {
						ClerkTrace("Pic", myIndex, "Cust", mySSN, "Takes picture of Customer again.\n");

					} else {
						ClerkTrace("Pic", myIndex, "Sen", mySSN, "Takes picture of Senator again.\n");
					}
					ServerRelease(traceLock, 0);
				}
			}


			/* file picture using
			* current thread yield
			
			for(i = 0; i < 20; i++){
				Yield();
			}*/
			ServerAcquire(traceLock, 0);
			if (cType == 0) {
				ClerkTrace("Pic", myIndex, "Cust", mySSN, "Informs Customer that the picture has been completed.\n");
			} else {
				ClerkTrace("Pic", myIndex, "Sen", mySSN, "Informs Senator that the picture has been completed.\n");
			}
			ServerRelease(traceLock, 0);

			/* signal customer awake */
			ServerAcquire(picMoneyLock, 0);
			SetMV(picMoney, 0, GetMV(picMoney, 0) + 500);

			ServerAcquire(traceLock, 0);
			if (cType == 0) {
				ClerkTrace("Pic", myIndex, "Cust", mySSN, "Accepts $500 from Customer.\n");
			} else {
				ClerkTrace("Pic", myIndex, "Cust", mySSN, "Accepts $500 from Senator.\n");
			}
			ServerRelease(traceLock, 0);

			ServerRelease(picMoneyLock, 0);

			SetMV(picDataBool, myIndex, 0);
			ServerSignal(picCV, myIndex, picLock, myIndex); /* signal customer awake */
			ServerRelease(picLock, myIndex); /* release clerk lock */
		}
		/* Check for regular customer line next
		* If there are regular customers, do PicClerk tasks
		*/
		else if(GetMV(regPCLineLength,0) > 0){
			SetMV(regPCLineLength, 0, GetMV(regPCLineLength, 0)-1);

			ServerAcquire(senatorLock, 0);
			SetMV(numPicWait, 0, GetMV(numPicWait, 0)+1);	/* shows customer that one clerk is waiting */
			ServerRelease(senatorLock, 0);

			ServerAcquire(picLock, myIndex);
			SetMV(picState, myIndex, 0); /* 0  = AVAILABLE */
			ServerSignal(regPCLineCV, 0, acpcLineLock, 0);
			ServerRelease(acpcLineLock, 0);
			
			ServerWait(picCV, myIndex, picLock, myIndex);	/* Waits for the next customer */

			mySSN = GetMV(picData, myIndex);
			/* check the customer type */
			ServerAcquire(fileLock, mySSN);
			if (GetMV(fileType, mySSN) == 0) {
				cType = 0;
			} else {
				cType = 1;
			}

			if(GetMV(fileState, mySSN) == 0){	/* 0 = NONE */
				SetMV(fileState, mySSN, 1);/* 1 = PICDONE */
				ServerRelease(fileLock, mySSN);
			}
			else if(GetMV(fileState, mySSN) == 2 ){ /* 2 = APPDONE */
				SetMV(fileState, mySSN, 3); /* 3 = APPPICDONE */
				ServerRelease(fileLock, mySSN);
			}
			else{
				ServerAcquire(traceLock, 0);
				ClerkTrace("Pic", myIndex, "Cust", mySSN,
					"ERROR: Customer does not have either an application or no application. What are you doing here?\n");
				ServerRelease(traceLock, 0);
				ServerRelease(fileLock, mySSN);
			}

			ServerAcquire(traceLock, 0);
			if (cType == 0) {
				ClerkTrace("Pic", myIndex, "Cust", mySSN, "Takes picture of Customer.\n");
			} else {
				ClerkTrace("Pic", myIndex, "Sen", mySSN, "Takes picture of Senator.\n");
			}
			ServerRelease(traceLock, 0);
			
				/* yield to take picture
				* print statement: "Taking picture"
				* picCV->Signal then picCV->Wait to
				* show customer picture
				*/
			while(GetMV(picDataBool, myIndex) == 0){
				for(i = 0; i < 4; i++){
					Yield();
				}
				ServerSignal(picCV, myIndex, picLock, myIndex);	
				ServerWait(picCV, myIndex, picLock, myIndex);	/* Shows the customer the picture */

				if(GetMV(picDataBool, myIndex) == 0){
					ServerAcquire(traceLock, 0);
					if (cType == 0) {
						ClerkTrace("Pic", myIndex, "Cust", mySSN, "Takes picture of Customer again.\n");
					} else {
						ClerkTrace("Pic", myIndex, "Sen", mySSN, "Takes picture of Senator again.\n");
					}
					ServerRelease(traceLock, 0);
				}
			}


			/* file picture using
			* current thread yield
			
			for(i = 0; i < 20; i++){
				Yield();
			}*/
			ServerAcquire(traceLock, 0);
			if (cType == 0) {
				ClerkTrace("Pic", myIndex, "Cust", mySSN, "Informs Customer that the picture has been completed.\n");
			} else {
				ClerkTrace("Pic", myIndex, "Sen", mySSN, "Informs Senator that the picture has been completed.\n");
			}
			ServerRelease(traceLock, 0);

			SetMV(picDataBool, myIndex, 0);
			ServerSignal(picCV, myIndex, picLock, myIndex); /* signal customer awake */
			ServerRelease(picLock, myIndex); /* release clerk lock */
		}		
		/* If there are neither privileged or regular customers, go on break */
		else{
			ServerRelease(acpcLineLock, 0);
			ServerAcquire(picLock, myIndex);
			SetMV(picState, myIndex, 2); /* 2 = BREAK */
			
			ServerAcquire(traceLock, 0);
			ClerkTrace("Pic", myIndex, 0x00, 0, "Going on break.\n");
			ServerRelease(traceLock, 0);

			ServerWait(picCV, myIndex, picLock, myIndex);
			
			ServerAcquire(traceLock, 0);
			ClerkTrace("Pic", myIndex, 0x00, 0, "Returning from break.\n");
			ServerRelease(traceLock, 0);
			
			ServerRelease(picLock, myIndex);
		}
	}
}
コード例 #28
0
int main()
{
    Print("Stress test begins..\n",-1,-1,-1);
    lock[0] = CreateLock("lock0");
    cv[0] = CreateCV("cv0");
    mv[0] = CreateMV("mv0");
    lock[1] = CreateLock("lock1");
    cv[1] = CreateCV("cv1");
    mv[1] = CreateMV("mv1");
    lock[2] = CreateLock("lock2");
    cv[2] = CreateCV("cv2");
    mv[2] = CreateMV("mv2");
    lock[3] = CreateLock("lock3");
    cv[3] = CreateCV("cv3");
    mv[3] = CreateMV("mv3");
    lock[4] = CreateLock("lock4");
    cv[4] = CreateCV("cv4");
    mv[4] = CreateMV("mv4");
    lock[5] = CreateLock("lock5");
    cv[5] = CreateCV("cv5");
    mv[5] = CreateMV("mv5");
    lock[6] = CreateLock("lock6");
    cv[6] = CreateCV("cv6");
    mv[6] = CreateMV("mv6");
    lock[7] = CreateLock("lock7");
    cv[7] = CreateCV("cv7");
    mv[7] = CreateMV("mv7");
    lock[8] = CreateLock("lock8");
    cv[8] = CreateCV("cv8");
    mv[8] = CreateMV("mv8");
    lock[9] = CreateLock("lock9");
    cv[9] = CreateCV("cv9");
    mv[9] = CreateMV("mv9");
    lock[10] = CreateLock("lock10");
    cv[10] = CreateCV("cv10");
    mv[10] = CreateMV("mv10");
    lock[11] = CreateLock("lock11");
    cv[11] = CreateCV("cv11");
    mv[11] = CreateMV("mv11");
    lock[12] = CreateLock("lock12");
    cv[12] = CreateCV("cv12");
    mv[12] = CreateMV("mv12");
    lock[13] = CreateLock("lock13");
    cv[13] = CreateCV("cv13");
    mv[13] = CreateMV("mv13");
    lock[14] = CreateLock("lock14");
    cv[14] = CreateCV("cv14");
    mv[14] = CreateMV("mv14");
    lock[15] = CreateLock("lock15");
    cv[15] = CreateCV("cv15");
    mv[15] = CreateMV("mv15");
    lock[16] = CreateLock("lock16");
    cv[16] = CreateCV("cv16");
    mv[16] = CreateMV("mv16");
    lock[17] = CreateLock("lock17");
    cv[17] = CreateCV("cv17");
    mv[17] = CreateMV("mv17");
    lock[18] = CreateLock("lock18");
    cv[18] = CreateCV("cv18");
    mv[18] = CreateMV("mv18");
    lock[19] = CreateLock("lock19");
    cv[19] = CreateCV("cv19");
    mv[19] = CreateMV("mv19");
    lock[20] = CreateLock("lock20");
    cv[20] = CreateCV("cv20");
    mv[20] = CreateMV("mv20");
    lock[21] = CreateLock("lock21");
    cv[21] = CreateCV("cv21");
    mv[21] = CreateMV("mv21");
    lock[22] = CreateLock("lock22");
    cv[22] = CreateCV("cv22");
    mv[22] = CreateMV("mv22");
    lock[23] = CreateLock("lock23");
    cv[23] = CreateCV("cv23");
    mv[23] = CreateMV("mv23");
    lock[24] = CreateLock("lock24");
    cv[24] = CreateCV("cv24");
    mv[24] = CreateMV("mv24");
    lock[25] = CreateLock("lock25");
    cv[25] = CreateCV("cv25");
    mv[25] = CreateMV("mv25");
    lock[26] = CreateLock("lock26");
    cv[26] = CreateCV("cv26");
    mv[26] = CreateMV("mv26");
    lock[27] = CreateLock("lock27");
    cv[27] = CreateCV("cv27");
    mv[27] = CreateMV("mv27");
    lock[28] = CreateLock("lock28");
    cv[28] = CreateCV("cv28");
    mv[28] = CreateMV("mv28");
    lock[29] = CreateLock("lock29");
    cv[29] = CreateCV("cv29");
    mv[29] = CreateMV("mv29");
    lock[30] = CreateLock("lock30");
    cv[30] = CreateCV("cv30");
    mv[30] = CreateMV("mv30");
    lock[31] = CreateLock("lock31");
    cv[31] = CreateCV("cv31");
    mv[31] = CreateMV("mv31");
    lock[32] = CreateLock("lock32");
    cv[32] = CreateCV("cv32");
    mv[32] = CreateMV("mv32");
    lock[33] = CreateLock("lock33");
    cv[33] = CreateCV("cv33");
    mv[33] = CreateMV("mv33");
    lock[34] = CreateLock("lock34");
    cv[34] = CreateCV("cv34");
    mv[34] = CreateMV("mv34");
    lock[35] = CreateLock("lock35");
    cv[35] = CreateCV("cv35");
    mv[35] = CreateMV("mv35");
    lock[36] = CreateLock("lock36");
    cv[36] = CreateCV("cv36");
    mv[36] = CreateMV("mv36");
    lock[37] = CreateLock("lock37");
    cv[37] = CreateCV("cv37");
    mv[37] = CreateMV("mv37");
    lock[38] = CreateLock("lock38");
    cv[38] = CreateCV("cv38");
    mv[38] = CreateMV("mv38");
    lock[39] = CreateLock("lock39");
    cv[39] = CreateCV("cv39");
    mv[39] = CreateMV("mv39");
    lock[40] = CreateLock("lock40");
    cv[40] = CreateCV("cv40");
    mv[40] = CreateMV("mv40");
    lock[41] = CreateLock("lock41");
    cv[41] = CreateCV("cv41");
    mv[41] = CreateMV("mv41");
    lock[42] = CreateLock("lock42");
    cv[42] = CreateCV("cv42");
    mv[42] = CreateMV("mv42");
    lock[43] = CreateLock("lock43");
    cv[43] = CreateCV("cv43");
    mv[43] = CreateMV("mv43");
    lock[44] = CreateLock("lock44");
    cv[44] = CreateCV("cv44");
    mv[44] = CreateMV("mv44");
    lock[45] = CreateLock("lock45");
    cv[45] = CreateCV("cv45");
    mv[45] = CreateMV("mv45");
    lock[46] = CreateLock("lock46");
    cv[46] = CreateCV("cv46");
    mv[46] = CreateMV("mv46");
    lock[47] = CreateLock("lock47");
    cv[47] = CreateCV("cv47");
    mv[47] = CreateMV("mv47");
    lock[48] = CreateLock("lock48");
    cv[48] = CreateCV("cv48");
    mv[48] = CreateMV("mv48");
    lock[49] = CreateLock("lock49");
    cv[49] = CreateCV("cv49");
    mv[49] = CreateMV("mv49");
    lock[50] = CreateLock("lock50");
    cv[50] = CreateCV("cv50");
    mv[50] = CreateMV("mv50");
    lock[51] = CreateLock("lock51");
    cv[51] = CreateCV("cv51");
    mv[51] = CreateMV("mv51");
    lock[52] = CreateLock("lock52");
    cv[52] = CreateCV("cv52");
    mv[52] = CreateMV("mv52");
    lock[53] = CreateLock("lock53");
    cv[53] = CreateCV("cv53");
    mv[53] = CreateMV("mv53");
    lock[54] = CreateLock("lock54");
    cv[54] = CreateCV("cv54");
    mv[54] = CreateMV("mv54");
    lock[55] = CreateLock("lock55");
    cv[55] = CreateCV("cv55");
    mv[55] = CreateMV("mv55");
    lock[56] = CreateLock("lock56");
    cv[56] = CreateCV("cv56");
    mv[56] = CreateMV("mv56");
    lock[57] = CreateLock("lock57");
    cv[57] = CreateCV("cv57");
    mv[57] = CreateMV("mv57");
    lock[58] = CreateLock("lock58");
    cv[58] = CreateCV("cv58");
    mv[58] = CreateMV("mv58");
    lock[59] = CreateLock("lock59");
    cv[59] = CreateCV("cv59");
    mv[59] = CreateMV("mv59");
    lock[60] = CreateLock("lock60");
    cv[60] = CreateCV("cv60");
    mv[60] = CreateMV("mv60");
    lock[61] = CreateLock("lock61");
    cv[61] = CreateCV("cv61");
    mv[61] = CreateMV("mv61");
    lock[62] = CreateLock("lock62");
    cv[62] = CreateCV("cv62");
    mv[62] = CreateMV("mv62");
    lock[63] = CreateLock("lock63");
    cv[63] = CreateCV("cv63");
    mv[63] = CreateMV("mv63");
    lock[64] = CreateLock("lock64");
    cv[64] = CreateCV("cv64");
    mv[64] = CreateMV("mv64");
    lock[65] = CreateLock("lock65");
    cv[65] = CreateCV("cv65");
    mv[65] = CreateMV("mv65");
    lock[66] = CreateLock("lock66");
    cv[66] = CreateCV("cv66");
    mv[66] = CreateMV("mv66");
    lock[67] = CreateLock("lock67");
    cv[67] = CreateCV("cv67");
    mv[67] = CreateMV("mv67");
    lock[68] = CreateLock("lock68");
    cv[68] = CreateCV("cv68");
    mv[68] = CreateMV("mv68");
    lock[69] = CreateLock("lock69");
    cv[69] = CreateCV("cv69");
    mv[69] = CreateMV("mv69");
    lock[70] = CreateLock("lock70");
    cv[70] = CreateCV("cv70");
    mv[70] = CreateMV("mv70");
    lock[71] = CreateLock("lock71");
    cv[71] = CreateCV("cv71");
    mv[71] = CreateMV("mv71");
    lock[72] = CreateLock("lock72");
    cv[72] = CreateCV("cv72");
    mv[72] = CreateMV("mv72");
    lock[73] = CreateLock("lock73");
    cv[73] = CreateCV("cv73");
    mv[73] = CreateMV("mv73");
    lock[74] = CreateLock("lock74");
    cv[74] = CreateCV("cv74");
    mv[74] = CreateMV("mv74");
    lock[75] = CreateLock("lock75");
    cv[75] = CreateCV("cv75");
    mv[75] = CreateMV("mv75");
    lock[76] = CreateLock("lock76");
    cv[76] = CreateCV("cv76");
    mv[76] = CreateMV("mv76");
    lock[77] = CreateLock("lock77");
    cv[77] = CreateCV("cv77");
    mv[77] = CreateMV("mv77");
    lock[78] = CreateLock("lock78");
    cv[78] = CreateCV("cv78");
    mv[78] = CreateMV("mv78");
    lock[79] = CreateLock("lock79");
    cv[79] = CreateCV("cv79");
    mv[79] = CreateMV("mv79");
    lock[80] = CreateLock("lock80");
    cv[80] = CreateCV("cv80");
    mv[80] = CreateMV("mv80");
    lock[81] = CreateLock("lock81");
    cv[81] = CreateCV("cv81");
    mv[81] = CreateMV("mv81");
    lock[82] = CreateLock("lock82");
    cv[82] = CreateCV("cv82");
    mv[82] = CreateMV("mv82");
    lock[83] = CreateLock("lock83");
    cv[83] = CreateCV("cv83");
    mv[83] = CreateMV("mv83");
    lock[84] = CreateLock("lock84");
    cv[84] = CreateCV("cv84");
    mv[84] = CreateMV("mv84");
    lock[85] = CreateLock("lock85");
    cv[85] = CreateCV("cv85");
    mv[85] = CreateMV("mv85");
    lock[86] = CreateLock("lock86");
    cv[86] = CreateCV("cv86");
    mv[86] = CreateMV("mv86");
    lock[87] = CreateLock("lock87");
    cv[87] = CreateCV("cv87");
    mv[87] = CreateMV("mv87");
    lock[88] = CreateLock("lock88");
    cv[88] = CreateCV("cv88");
    mv[88] = CreateMV("mv88");
    lock[89] = CreateLock("lock89");
    cv[89] = CreateCV("cv89");
    mv[89] = CreateMV("mv89");
    lock[90] = CreateLock("lock90");
    cv[90] = CreateCV("cv90");
    mv[90] = CreateMV("mv90");
    lock[91] = CreateLock("lock91");
    cv[91] = CreateCV("cv91");
    mv[91] = CreateMV("mv91");
    lock[92] = CreateLock("lock92");
    cv[92] = CreateCV("cv92");
    mv[92] = CreateMV("mv92");
    lock[93] = CreateLock("lock93");
    cv[93] = CreateCV("cv93");
    mv[93] = CreateMV("mv93");
    lock[94] = CreateLock("lock94");
    cv[94] = CreateCV("cv94");
    mv[94] = CreateMV("mv94");
    lock[95] = CreateLock("lock95");
    cv[95] = CreateCV("cv95");
    mv[95] = CreateMV("mv95");
    lock[96] = CreateLock("lock96");
    cv[96] = CreateCV("cv96");
    mv[96] = CreateMV("mv96");
    lock[97] = CreateLock("lock97");
    cv[97] = CreateCV("cv97");
    mv[97] = CreateMV("mv97");
    lock[98] = CreateLock("lock98");
    cv[98] = CreateCV("cv98");
    mv[98] = CreateMV("mv98");
    lock[99] = CreateLock("lock99");
    cv[99] = CreateCV("cv99");
    mv[99] = CreateMV("mv99");
    lock[100] = CreateLock("lock100");
    cv[100] = CreateCV("cv100");
    mv[100] = CreateMV("mv100");
    lock[101] = CreateLock("lock101");
    cv[101] = CreateCV("cv101");
    mv[101] = CreateMV("mv101");
    lock[102] = CreateLock("lock102");
    cv[102] = CreateCV("cv102");
    mv[102] = CreateMV("mv102");
    lock[103] = CreateLock("lock103");
    cv[103] = CreateCV("cv103");
    mv[103] = CreateMV("mv103");
    lock[104] = CreateLock("lock104");
    cv[104] = CreateCV("cv104");
    mv[104] = CreateMV("mv104");
    lock[105] = CreateLock("lock105");
    cv[105] = CreateCV("cv105");
    mv[105] = CreateMV("mv105");
    lock[106] = CreateLock("lock106");
    cv[106] = CreateCV("cv106");
    mv[106] = CreateMV("mv106");
    lock[107] = CreateLock("lock107");
    cv[107] = CreateCV("cv107");
    mv[107] = CreateMV("mv107");
    lock[108] = CreateLock("lock108");
    cv[108] = CreateCV("cv108");
    mv[108] = CreateMV("mv108");
    lock[109] = CreateLock("lock109");
    cv[109] = CreateCV("cv109");
    mv[109] = CreateMV("mv109");
    lock[110] = CreateLock("lock110");
    cv[110] = CreateCV("cv110");
    mv[110] = CreateMV("mv110");
    lock[111] = CreateLock("lock111");
    cv[111] = CreateCV("cv111");
    mv[111] = CreateMV("mv111");
    lock[112] = CreateLock("lock112");
    cv[112] = CreateCV("cv112");
    mv[112] = CreateMV("mv112");
    lock[113] = CreateLock("lock113");
    cv[113] = CreateCV("cv113");
    mv[113] = CreateMV("mv113");
    lock[114] = CreateLock("lock114");
    cv[114] = CreateCV("cv114");
    mv[114] = CreateMV("mv114");
    lock[115] = CreateLock("lock115");
    cv[115] = CreateCV("cv115");
    mv[115] = CreateMV("mv115");
    lock[116] = CreateLock("lock116");
    cv[116] = CreateCV("cv116");
    mv[116] = CreateMV("mv116");
    lock[117] = CreateLock("lock117");
    cv[117] = CreateCV("cv117");
    mv[117] = CreateMV("mv117");
    lock[118] = CreateLock("lock118");
    cv[118] = CreateCV("cv118");
    mv[118] = CreateMV("mv118");
    lock[119] = CreateLock("lock119");
    cv[119] = CreateCV("cv119");
    mv[119] = CreateMV("mv119");
    lock[120] = CreateLock("lock120");
    cv[120] = CreateCV("cv120");
    mv[120] = CreateMV("mv120");
    lock[121] = CreateLock("lock121");
    cv[121] = CreateCV("cv121");
    mv[121] = CreateMV("mv121");
    lock[122] = CreateLock("lock122");
    cv[122] = CreateCV("cv122");
    mv[122] = CreateMV("mv122");
    lock[123] = CreateLock("lock123");
    cv[123] = CreateCV("cv123");
    mv[123] = CreateMV("mv123");
    lock[124] = CreateLock("lock124");
    cv[124] = CreateCV("cv124");
    mv[124] = CreateMV("mv124");
    lock[125] = CreateLock("lock125");
    cv[125] = CreateCV("cv125");
    mv[125] = CreateMV("mv125");
    lock[126] = CreateLock("lock126");
    cv[126] = CreateCV("cv126");
    mv[126] = CreateMV("mv126");
    lock[127] = CreateLock("lock127");
    cv[127] = CreateCV("cv127");
    mv[127] = CreateMV("mv127");
    lock[128] = CreateLock("lock128");
    cv[128] = CreateCV("cv128");
    mv[128] = CreateMV("mv128");
    lock[129] = CreateLock("lock129");
    cv[129] = CreateCV("cv129");
    mv[129] = CreateMV("mv129");
    lock[130] = CreateLock("lock130");
    cv[130] = CreateCV("cv130");
    mv[130] = CreateMV("mv130");
    lock[131] = CreateLock("lock131");
    cv[131] = CreateCV("cv131");
    mv[131] = CreateMV("mv131");
    lock[132] = CreateLock("lock132");
    cv[132] = CreateCV("cv132");
    mv[132] = CreateMV("mv132");
    lock[133] = CreateLock("lock133");
    cv[133] = CreateCV("cv133");
    mv[133] = CreateMV("mv133");
    lock[134] = CreateLock("lock134");
    cv[134] = CreateCV("cv134");
    mv[134] = CreateMV("mv134");
    lock[135] = CreateLock("lock135");
    cv[135] = CreateCV("cv135");
    mv[135] = CreateMV("mv135");
    lock[136] = CreateLock("lock136");
    cv[136] = CreateCV("cv136");
    mv[136] = CreateMV("mv136");
    lock[137] = CreateLock("lock137");
    cv[137] = CreateCV("cv137");
    mv[137] = CreateMV("mv137");
    lock[138] = CreateLock("lock138");
    cv[138] = CreateCV("cv138");
    mv[138] = CreateMV("mv138");
    lock[139] = CreateLock("lock139");
    cv[139] = CreateCV("cv139");
    mv[139] = CreateMV("mv139");
    lock[140] = CreateLock("lock140");
    cv[140] = CreateCV("cv140");
    mv[140] = CreateMV("mv140");
    lock[141] = CreateLock("lock141");
    cv[141] = CreateCV("cv141");
    mv[141] = CreateMV("mv141");
    lock[142] = CreateLock("lock142");
    cv[142] = CreateCV("cv142");
    mv[142] = CreateMV("mv142");
    lock[143] = CreateLock("lock143");
    cv[143] = CreateCV("cv143");
    mv[143] = CreateMV("mv143");
    lock[144] = CreateLock("lock144");
    cv[144] = CreateCV("cv144");
    mv[144] = CreateMV("mv144");
    lock[145] = CreateLock("lock145");
    cv[145] = CreateCV("cv145");
    mv[145] = CreateMV("mv145");
    lock[146] = CreateLock("lock146");
    cv[146] = CreateCV("cv146");
    mv[146] = CreateMV("mv146");
    lock[147] = CreateLock("lock147");
    cv[147] = CreateCV("cv147");
    mv[147] = CreateMV("mv147");
    lock[148] = CreateLock("lock148");
    cv[148] = CreateCV("cv148");
    mv[148] = CreateMV("mv148");
    lock[149] = CreateLock("lock149");
    cv[149] = CreateCV("cv149");
    mv[149] = CreateMV("mv149");
    lock[150] = CreateLock("lock150");
    cv[150] = CreateCV("cv150");
    mv[150] = CreateMV("mv150");
    lock[151] = CreateLock("lock151");
    cv[151] = CreateCV("cv151");
    mv[151] = CreateMV("mv151");
    lock[152] = CreateLock("lock152");
    cv[152] = CreateCV("cv152");
    mv[152] = CreateMV("mv152");
    lock[153] = CreateLock("lock153");
    cv[153] = CreateCV("cv153");
    mv[153] = CreateMV("mv153");
    lock[154] = CreateLock("lock154");
    cv[154] = CreateCV("cv154");
    mv[154] = CreateMV("mv154");
    lock[155] = CreateLock("lock155");
    cv[155] = CreateCV("cv155");
    mv[155] = CreateMV("mv155");
    lock[156] = CreateLock("lock156");
    cv[156] = CreateCV("cv156");
    mv[156] = CreateMV("mv156");
    lock[157] = CreateLock("lock157");
    cv[157] = CreateCV("cv157");
    mv[157] = CreateMV("mv157");
    lock[158] = CreateLock("lock158");
    cv[158] = CreateCV("cv158");
    mv[158] = CreateMV("mv158");
    lock[159] = CreateLock("lock159");
    cv[159] = CreateCV("cv159");
    mv[159] = CreateMV("mv159");
    lock[160] = CreateLock("lock160");
    cv[160] = CreateCV("cv160");
    mv[160] = CreateMV("mv160");
    lock[161] = CreateLock("lock161");
    cv[161] = CreateCV("cv161");
    mv[161] = CreateMV("mv161");
    lock[162] = CreateLock("lock162");
    cv[162] = CreateCV("cv162");
    mv[162] = CreateMV("mv162");
    lock[163] = CreateLock("lock163");
    cv[163] = CreateCV("cv163");
    mv[163] = CreateMV("mv163");
    lock[164] = CreateLock("lock164");
    cv[164] = CreateCV("cv164");
    mv[164] = CreateMV("mv164");
    lock[165] = CreateLock("lock165");
    cv[165] = CreateCV("cv165");
    mv[165] = CreateMV("mv165");
    lock[166] = CreateLock("lock166");
    cv[166] = CreateCV("cv166");
    mv[166] = CreateMV("mv166");
    lock[167] = CreateLock("lock167");
    cv[167] = CreateCV("cv167");
    mv[167] = CreateMV("mv167");
    lock[168] = CreateLock("lock168");
    cv[168] = CreateCV("cv168");
    mv[168] = CreateMV("mv168");
    lock[169] = CreateLock("lock169");
    cv[169] = CreateCV("cv169");
    mv[169] = CreateMV("mv169");
    lock[170] = CreateLock("lock170");
    cv[170] = CreateCV("cv170");
    mv[170] = CreateMV("mv170");
    lock[171] = CreateLock("lock171");
    cv[171] = CreateCV("cv171");
    mv[171] = CreateMV("mv171");
    lock[172] = CreateLock("lock172");
    cv[172] = CreateCV("cv172");
    mv[172] = CreateMV("mv172");
    lock[173] = CreateLock("lock173");
    cv[173] = CreateCV("cv173");
    mv[173] = CreateMV("mv173");
    lock[174] = CreateLock("lock174");
    cv[174] = CreateCV("cv174");
    mv[174] = CreateMV("mv174");
    lock[175] = CreateLock("lock175");
    cv[175] = CreateCV("cv175");
    mv[175] = CreateMV("mv175");
    lock[176] = CreateLock("lock176");
    cv[176] = CreateCV("cv176");
    mv[176] = CreateMV("mv176");
    lock[177] = CreateLock("lock177");
    cv[177] = CreateCV("cv177");
    mv[177] = CreateMV("mv177");
    lock[178] = CreateLock("lock178");
    cv[178] = CreateCV("cv178");
    mv[178] = CreateMV("mv178");
    lock[179] = CreateLock("lock179");
    cv[179] = CreateCV("cv179");
    mv[179] = CreateMV("mv179");
    lock[180] = CreateLock("lock180");
    cv[180] = CreateCV("cv180");
    mv[180] = CreateMV("mv180");
    lock[181] = CreateLock("lock181");
    cv[181] = CreateCV("cv181");
    mv[181] = CreateMV("mv181");
    lock[182] = CreateLock("lock182");
    cv[182] = CreateCV("cv182");
    mv[182] = CreateMV("mv182");
    lock[183] = CreateLock("lock183");
    cv[183] = CreateCV("cv183");
    mv[183] = CreateMV("mv183");
    lock[184] = CreateLock("lock184");
    cv[184] = CreateCV("cv184");
    mv[184] = CreateMV("mv184");
    lock[185] = CreateLock("lock185");
    cv[185] = CreateCV("cv185");
    mv[185] = CreateMV("mv185");
    lock[186] = CreateLock("lock186");
    cv[186] = CreateCV("cv186");
    mv[186] = CreateMV("mv186");
    lock[187] = CreateLock("lock187");
    cv[187] = CreateCV("cv187");
    mv[187] = CreateMV("mv187");
    lock[188] = CreateLock("lock188");
    cv[188] = CreateCV("cv188");
    mv[188] = CreateMV("mv188");
    lock[189] = CreateLock("lock189");
    cv[189] = CreateCV("cv189");
    mv[189] = CreateMV("mv189");
    lock[190] = CreateLock("lock190");
    cv[190] = CreateCV("cv190");
    mv[190] = CreateMV("mv190");
    lock[191] = CreateLock("lock191");
    cv[191] = CreateCV("cv191");
    mv[191] = CreateMV("mv191");
    lock[192] = CreateLock("lock192");
    cv[192] = CreateCV("cv192");
    mv[192] = CreateMV("mv192");
    lock[193] = CreateLock("lock193");
    cv[193] = CreateCV("cv193");
    mv[193] = CreateMV("mv193");
    lock[194] = CreateLock("lock194");
    cv[194] = CreateCV("cv194");
    mv[194] = CreateMV("mv194");
    lock[195] = CreateLock("lock195");
    cv[195] = CreateCV("cv195");
    mv[195] = CreateMV("mv195");
    lock[196] = CreateLock("lock196");
    cv[196] = CreateCV("cv196");
    mv[196] = CreateMV("mv196");
    lock[197] = CreateLock("lock197");
    cv[197] = CreateCV("cv197");
    mv[197] = CreateMV("mv197");
    lock[198] = CreateLock("lock198");
    cv[198] = CreateCV("cv198");
    mv[198] = CreateMV("mv198");
    lock[199] = CreateLock("lock199");
    cv[199] = CreateCV("cv199");
    mv[199] = CreateMV("mv199");
    lock[200] = CreateLock("lock200");
    cv[200] = CreateCV("cv200");
    mv[200] = CreateMV("mv200");
    lock[201] = CreateLock("lock201");
    cv[201] = CreateCV("cv201");
    mv[201] = CreateMV("mv201");
    lock[202] = CreateLock("lock202");
    cv[202] = CreateCV("cv202");
    mv[202] = CreateMV("mv202");
    lock[203] = CreateLock("lock203");
    cv[203] = CreateCV("cv203");
    mv[203] = CreateMV("mv203");
    lock[204] = CreateLock("lock204");
    cv[204] = CreateCV("cv204");
    mv[204] = CreateMV("mv204");
    lock[205] = CreateLock("lock205");
    cv[205] = CreateCV("cv205");
    mv[205] = CreateMV("mv205");
    lock[206] = CreateLock("lock206");
    cv[206] = CreateCV("cv206");
    mv[206] = CreateMV("mv206");
    lock[207] = CreateLock("lock207");
    cv[207] = CreateCV("cv207");
    mv[207] = CreateMV("mv207");
    lock[208] = CreateLock("lock208");
    cv[208] = CreateCV("cv208");
    mv[208] = CreateMV("mv208");
    lock[209] = CreateLock("lock209");
    cv[209] = CreateCV("cv209");
    mv[209] = CreateMV("mv209");
    lock[210] = CreateLock("lock210");
    cv[210] = CreateCV("cv210");
    mv[210] = CreateMV("mv210");
    lock[211] = CreateLock("lock211");
    cv[211] = CreateCV("cv211");
    mv[211] = CreateMV("mv211");
    lock[212] = CreateLock("lock212");
    cv[212] = CreateCV("cv212");
    mv[212] = CreateMV("mv212");
    lock[213] = CreateLock("lock213");
    cv[213] = CreateCV("cv213");
    mv[213] = CreateMV("mv213");
    lock[214] = CreateLock("lock214");
    cv[214] = CreateCV("cv214");
    mv[214] = CreateMV("mv214");
    lock[215] = CreateLock("lock215");
    cv[215] = CreateCV("cv215");
    mv[215] = CreateMV("mv215");
    lock[216] = CreateLock("lock216");
    cv[216] = CreateCV("cv216");
    mv[216] = CreateMV("mv216");
    lock[217] = CreateLock("lock217");
    cv[217] = CreateCV("cv217");
    mv[217] = CreateMV("mv217");
    lock[218] = CreateLock("lock218");
    cv[218] = CreateCV("cv218");
    mv[218] = CreateMV("mv218");
    lock[219] = CreateLock("lock219");
    cv[219] = CreateCV("cv219");
    mv[219] = CreateMV("mv219");
    lock[220] = CreateLock("lock220");
    cv[220] = CreateCV("cv220");
    mv[220] = CreateMV("mv220");
    lock[221] = CreateLock("lock221");
    cv[221] = CreateCV("cv221");
    mv[221] = CreateMV("mv221");
    lock[222] = CreateLock("lock222");
    cv[222] = CreateCV("cv222");
    mv[222] = CreateMV("mv222");
    lock[223] = CreateLock("lock223");
    cv[223] = CreateCV("cv223");
    mv[223] = CreateMV("mv223");
    lock[224] = CreateLock("lock224");
    cv[224] = CreateCV("cv224");
    mv[224] = CreateMV("mv224");
    lock[225] = CreateLock("lock225");
    cv[225] = CreateCV("cv225");
    mv[225] = CreateMV("mv225");
    lock[226] = CreateLock("lock226");
    cv[226] = CreateCV("cv226");
    mv[226] = CreateMV("mv226");
    lock[227] = CreateLock("lock227");
    cv[227] = CreateCV("cv227");
    mv[227] = CreateMV("mv227");
    lock[228] = CreateLock("lock228");
    cv[228] = CreateCV("cv228");
    mv[228] = CreateMV("mv228");
    lock[229] = CreateLock("lock229");
    cv[229] = CreateCV("cv229");
    mv[229] = CreateMV("mv229");
    lock[230] = CreateLock("lock230");
    cv[230] = CreateCV("cv230");
    mv[230] = CreateMV("mv230");
    lock[231] = CreateLock("lock231");
    cv[231] = CreateCV("cv231");
    mv[231] = CreateMV("mv231");
    lock[232] = CreateLock("lock232");
    cv[232] = CreateCV("cv232");
    mv[232] = CreateMV("mv232");
    lock[233] = CreateLock("lock233");
    cv[233] = CreateCV("cv233");
    mv[233] = CreateMV("mv233");
    lock[234] = CreateLock("lock234");
    cv[234] = CreateCV("cv234");
    mv[234] = CreateMV("mv234");
    lock[235] = CreateLock("lock235");
    cv[235] = CreateCV("cv235");
    mv[235] = CreateMV("mv235");
    lock[236] = CreateLock("lock236");
    cv[236] = CreateCV("cv236");
    mv[236] = CreateMV("mv236");
    lock[237] = CreateLock("lock237");
    cv[237] = CreateCV("cv237");
    mv[237] = CreateMV("mv237");
    lock[238] = CreateLock("lock238");
    cv[238] = CreateCV("cv238");
    mv[238] = CreateMV("mv238");
    lock[239] = CreateLock("lock239");
    cv[239] = CreateCV("cv239");
    mv[239] = CreateMV("mv239");
    lock[240] = CreateLock("lock240");
    cv[240] = CreateCV("cv240");
    mv[240] = CreateMV("mv240");
    lock[241] = CreateLock("lock241");
    cv[241] = CreateCV("cv241");
    mv[241] = CreateMV("mv241");
    lock[242] = CreateLock("lock242");
    cv[242] = CreateCV("cv242");
    mv[242] = CreateMV("mv242");
    lock[243] = CreateLock("lock243");
    cv[243] = CreateCV("cv243");
    mv[243] = CreateMV("mv243");
    lock[244] = CreateLock("lock244");
    cv[244] = CreateCV("cv244");
    mv[244] = CreateMV("mv244");
    lock[245] = CreateLock("lock245");
    cv[245] = CreateCV("cv245");
    mv[245] = CreateMV("mv245");
    lock[246] = CreateLock("lock246");
    cv[246] = CreateCV("cv246");
    mv[246] = CreateMV("mv246");
    lock[247] = CreateLock("lock247");
    cv[247] = CreateCV("cv247");
    mv[247] = CreateMV("mv247");
    lock[248] = CreateLock("lock248");
    cv[248] = CreateCV("cv248");
    mv[248] = CreateMV("mv248");
    lock[249] = CreateLock("lock249");
    cv[249] = CreateCV("cv249");
    mv[249] = CreateMV("mv249");

    lock[250] = CreateLock("lock250");
    cv[250] = CreateCV("cv250");
    mv[250] = CreateMV("mv250");

    AcquireLock("lock0");
    AcquireLock("lock1");
    AcquireLock("lock2");
    AcquireLock("lock3");
    AcquireLock("lock4");
    AcquireLock("lock5");
    AcquireLock("lock6");
    AcquireLock("lock7");
    AcquireLock("lock8");
    AcquireLock("lock9");
    AcquireLock("lock10");
    AcquireLock("lock11");
    AcquireLock("lock12");
    AcquireLock("lock13");
    AcquireLock("lock14");
    AcquireLock("lock15");
    AcquireLock("lock16");
    AcquireLock("lock17");
    AcquireLock("lock18");
    AcquireLock("lock19");
    AcquireLock("lock20");
    AcquireLock("lock21");
    AcquireLock("lock22");
    AcquireLock("lock23");
    AcquireLock("lock24");
    AcquireLock("lock25");
    AcquireLock("lock26");
    AcquireLock("lock27");
    AcquireLock("lock28");
    AcquireLock("lock29");
    AcquireLock("lock30");
    AcquireLock("lock31");
    AcquireLock("lock32");
    AcquireLock("lock33");
    AcquireLock("lock34");
    AcquireLock("lock35");
    AcquireLock("lock36");
    AcquireLock("lock37");
    AcquireLock("lock38");
    AcquireLock("lock39");
    AcquireLock("lock40");
    AcquireLock("lock41");
    AcquireLock("lock42");
    AcquireLock("lock43");
    AcquireLock("lock44");
    AcquireLock("lock45");
    AcquireLock("lock46");
    AcquireLock("lock47");
    AcquireLock("lock48");
    AcquireLock("lock49");
    AcquireLock("lock50");
    AcquireLock("lock51");
    AcquireLock("lock52");
    AcquireLock("lock53");
    AcquireLock("lock54");
    AcquireLock("lock55");
    AcquireLock("lock56");
    AcquireLock("lock57");
    AcquireLock("lock58");
    AcquireLock("lock59");
    AcquireLock("lock60");
    AcquireLock("lock61");
    AcquireLock("lock62");
    AcquireLock("lock63");
    AcquireLock("lock64");
    AcquireLock("lock65");
    AcquireLock("lock66");
    AcquireLock("lock67");
    AcquireLock("lock68");
    AcquireLock("lock69");
    AcquireLock("lock70");
    AcquireLock("lock71");
    AcquireLock("lock72");
    AcquireLock("lock73");
    AcquireLock("lock74");
    AcquireLock("lock75");
    AcquireLock("lock76");
    AcquireLock("lock77");
    AcquireLock("lock78");
    AcquireLock("lock79");
    AcquireLock("lock80");
    AcquireLock("lock81");
    AcquireLock("lock82");
    AcquireLock("lock83");
    AcquireLock("lock84");
    AcquireLock("lock85");
    AcquireLock("lock86");
    AcquireLock("lock87");
    AcquireLock("lock88");
    AcquireLock("lock89");
    AcquireLock("lock90");
    AcquireLock("lock91");
    AcquireLock("lock92");
    AcquireLock("lock93");
    AcquireLock("lock94");
    AcquireLock("lock95");
    AcquireLock("lock96");
    AcquireLock("lock97");
    AcquireLock("lock98");
    AcquireLock("lock99");
    AcquireLock("lock100");
    AcquireLock("lock101");
    AcquireLock("lock102");
    AcquireLock("lock103");
    AcquireLock("lock104");
    AcquireLock("lock105");
    AcquireLock("lock106");
    AcquireLock("lock107");
    AcquireLock("lock108");
    AcquireLock("lock109");
    AcquireLock("lock110");
    AcquireLock("lock111");
    AcquireLock("lock112");
    AcquireLock("lock113");
    AcquireLock("lock114");
    AcquireLock("lock115");
    AcquireLock("lock116");
    AcquireLock("lock117");
    AcquireLock("lock118");
    AcquireLock("lock119");
    AcquireLock("lock120");
    AcquireLock("lock121");
    AcquireLock("lock122");
    AcquireLock("lock123");
    AcquireLock("lock124");
    AcquireLock("lock125");
    AcquireLock("lock126");
    AcquireLock("lock127");
    AcquireLock("lock128");
    AcquireLock("lock129");
    AcquireLock("lock130");
    AcquireLock("lock131");
    AcquireLock("lock132");
    AcquireLock("lock133");
    AcquireLock("lock134");
    AcquireLock("lock135");
    AcquireLock("lock136");
    AcquireLock("lock137");
    AcquireLock("lock138");
    AcquireLock("lock139");
    AcquireLock("lock140");
    AcquireLock("lock141");
    AcquireLock("lock142");
    AcquireLock("lock143");
    AcquireLock("lock144");
    AcquireLock("lock145");
    AcquireLock("lock146");
    AcquireLock("lock147");
    AcquireLock("lock148");
    AcquireLock("lock149");
    AcquireLock("lock150");
    AcquireLock("lock151");
    AcquireLock("lock152");
    AcquireLock("lock153");
    AcquireLock("lock154");
    AcquireLock("lock155");
    AcquireLock("lock156");
    AcquireLock("lock157");
    AcquireLock("lock158");
    AcquireLock("lock159");
    AcquireLock("lock160");
    AcquireLock("lock161");
    AcquireLock("lock162");
    AcquireLock("lock163");
    AcquireLock("lock164");
    AcquireLock("lock165");
    AcquireLock("lock166");
    AcquireLock("lock167");
    AcquireLock("lock168");
    AcquireLock("lock169");
    AcquireLock("lock170");
    AcquireLock("lock171");
    AcquireLock("lock172");
    AcquireLock("lock173");
    AcquireLock("lock174");
    AcquireLock("lock175");
    AcquireLock("lock176");
    AcquireLock("lock177");
    AcquireLock("lock178");
    AcquireLock("lock179");
    AcquireLock("lock180");
    AcquireLock("lock181");
    AcquireLock("lock182");
    AcquireLock("lock183");
    AcquireLock("lock184");
    AcquireLock("lock185");
    AcquireLock("lock186");
    AcquireLock("lock187");
    AcquireLock("lock188");
    AcquireLock("lock189");
    AcquireLock("lock190");
    AcquireLock("lock191");
    AcquireLock("lock192");
    AcquireLock("lock193");
    AcquireLock("lock194");
    AcquireLock("lock195");
    AcquireLock("lock196");
    AcquireLock("lock197");
    AcquireLock("lock198");
    AcquireLock("lock199");
    AcquireLock("lock200");
    AcquireLock("lock201");
    AcquireLock("lock202");
    AcquireLock("lock203");
    AcquireLock("lock204");
    AcquireLock("lock205");
    AcquireLock("lock206");
    AcquireLock("lock207");
    AcquireLock("lock208");
    AcquireLock("lock209");
    AcquireLock("lock210");
    AcquireLock("lock211");
    AcquireLock("lock212");
    AcquireLock("lock213");
    AcquireLock("lock214");
    AcquireLock("lock215");
    AcquireLock("lock216");
    AcquireLock("lock217");
    AcquireLock("lock218");
    AcquireLock("lock219");
    AcquireLock("lock220");
    AcquireLock("lock221");
    AcquireLock("lock222");
    AcquireLock("lock223");
    AcquireLock("lock224");
    AcquireLock("lock225");
    AcquireLock("lock226");
    AcquireLock("lock227");
    AcquireLock("lock228");
    AcquireLock("lock229");
    AcquireLock("lock230");
    AcquireLock("lock231");
    AcquireLock("lock232");
    AcquireLock("lock233");
    AcquireLock("lock234");
    AcquireLock("lock235");
    AcquireLock("lock236");
    AcquireLock("lock237");
    AcquireLock("lock238");
    AcquireLock("lock239");
    AcquireLock("lock240");
    AcquireLock("lock241");
    AcquireLock("lock242");
    AcquireLock("lock243");
    AcquireLock("lock244");
    AcquireLock("lock245");
    AcquireLock("lock246");
    AcquireLock("lock247");
    AcquireLock("lock248");
    AcquireLock("lock249");

    ReleaseLock("lock0");
    ReleaseLock("lock1");
    ReleaseLock("lock2");
    ReleaseLock("lock3");
    ReleaseLock("lock4");
    ReleaseLock("lock5");
    ReleaseLock("lock6");
    ReleaseLock("lock7");
    ReleaseLock("lock8");
    ReleaseLock("lock9");
    ReleaseLock("lock10");
    ReleaseLock("lock11");
    ReleaseLock("lock12");
    ReleaseLock("lock13");
    ReleaseLock("lock14");
    ReleaseLock("lock15");
    ReleaseLock("lock16");
    ReleaseLock("lock17");
    ReleaseLock("lock18");
    ReleaseLock("lock19");
    ReleaseLock("lock20");
    ReleaseLock("lock21");
    ReleaseLock("lock22");
    ReleaseLock("lock23");
    ReleaseLock("lock24");
    ReleaseLock("lock25");
    ReleaseLock("lock26");
    ReleaseLock("lock27");
    ReleaseLock("lock28");
    ReleaseLock("lock29");
    ReleaseLock("lock30");
    ReleaseLock("lock31");
    ReleaseLock("lock32");
    ReleaseLock("lock33");
    ReleaseLock("lock34");
    ReleaseLock("lock35");
    ReleaseLock("lock36");
    ReleaseLock("lock37");
    ReleaseLock("lock38");
    ReleaseLock("lock39");
    ReleaseLock("lock40");
    ReleaseLock("lock41");
    ReleaseLock("lock42");
    ReleaseLock("lock43");
    ReleaseLock("lock44");
    ReleaseLock("lock45");
    ReleaseLock("lock46");
    ReleaseLock("lock47");
    ReleaseLock("lock48");
    ReleaseLock("lock49");
    ReleaseLock("lock50");
    ReleaseLock("lock51");
    ReleaseLock("lock52");
    ReleaseLock("lock53");
    ReleaseLock("lock54");
    ReleaseLock("lock55");
    ReleaseLock("lock56");
    ReleaseLock("lock57");
    ReleaseLock("lock58");
    ReleaseLock("lock59");
    ReleaseLock("lock60");
    ReleaseLock("lock61");
    ReleaseLock("lock62");
    ReleaseLock("lock63");
    ReleaseLock("lock64");
    ReleaseLock("lock65");
    ReleaseLock("lock66");
    ReleaseLock("lock67");
    ReleaseLock("lock68");
    ReleaseLock("lock69");
    ReleaseLock("lock70");
    ReleaseLock("lock71");
    ReleaseLock("lock72");
    ReleaseLock("lock73");
    ReleaseLock("lock74");
    ReleaseLock("lock75");
    ReleaseLock("lock76");
    ReleaseLock("lock77");
    ReleaseLock("lock78");
    ReleaseLock("lock79");
    ReleaseLock("lock80");
    ReleaseLock("lock81");
    ReleaseLock("lock82");
    ReleaseLock("lock83");
    ReleaseLock("lock84");
    ReleaseLock("lock85");
    ReleaseLock("lock86");
    ReleaseLock("lock87");
    ReleaseLock("lock88");
    ReleaseLock("lock89");
    ReleaseLock("lock90");
    ReleaseLock("lock91");
    ReleaseLock("lock92");
    ReleaseLock("lock93");
    ReleaseLock("lock94");
    ReleaseLock("lock95");
    ReleaseLock("lock96");
    ReleaseLock("lock97");
    ReleaseLock("lock98");
    ReleaseLock("lock99");
    ReleaseLock("lock100");
    ReleaseLock("lock101");
    ReleaseLock("lock102");
    ReleaseLock("lock103");
    ReleaseLock("lock104");
    ReleaseLock("lock105");
    ReleaseLock("lock106");
    ReleaseLock("lock107");
    ReleaseLock("lock108");
    ReleaseLock("lock109");
    ReleaseLock("lock110");
    ReleaseLock("lock111");
    ReleaseLock("lock112");
    ReleaseLock("lock113");
    ReleaseLock("lock114");
    ReleaseLock("lock115");
    ReleaseLock("lock116");
    ReleaseLock("lock117");
    ReleaseLock("lock118");
    ReleaseLock("lock119");
    ReleaseLock("lock120");
    ReleaseLock("lock121");
    ReleaseLock("lock122");
    ReleaseLock("lock123");
    ReleaseLock("lock124");
    ReleaseLock("lock125");
    ReleaseLock("lock126");
    ReleaseLock("lock127");
    ReleaseLock("lock128");
    ReleaseLock("lock129");
    ReleaseLock("lock130");
    ReleaseLock("lock131");
    ReleaseLock("lock132");
    ReleaseLock("lock133");
    ReleaseLock("lock134");
    ReleaseLock("lock135");
    ReleaseLock("lock136");
    ReleaseLock("lock137");
    ReleaseLock("lock138");
    ReleaseLock("lock139");
    ReleaseLock("lock140");
    ReleaseLock("lock141");
    ReleaseLock("lock142");
    ReleaseLock("lock143");
    ReleaseLock("lock144");
    ReleaseLock("lock145");
    ReleaseLock("lock146");
    ReleaseLock("lock147");
    ReleaseLock("lock148");
    ReleaseLock("lock149");
    ReleaseLock("lock150");
    ReleaseLock("lock151");
    ReleaseLock("lock152");
    ReleaseLock("lock153");
    ReleaseLock("lock154");
    ReleaseLock("lock155");
    ReleaseLock("lock156");
    ReleaseLock("lock157");
    ReleaseLock("lock158");
    ReleaseLock("lock159");
    ReleaseLock("lock160");
    ReleaseLock("lock161");
    ReleaseLock("lock162");
    ReleaseLock("lock163");
    ReleaseLock("lock164");
    ReleaseLock("lock165");
    ReleaseLock("lock166");
    ReleaseLock("lock167");
    ReleaseLock("lock168");
    ReleaseLock("lock169");
    ReleaseLock("lock170");
    ReleaseLock("lock171");
    ReleaseLock("lock172");
    ReleaseLock("lock173");
    ReleaseLock("lock174");
    ReleaseLock("lock175");
    ReleaseLock("lock176");
    ReleaseLock("lock177");
    ReleaseLock("lock178");
    ReleaseLock("lock179");
    ReleaseLock("lock180");
    ReleaseLock("lock181");
    ReleaseLock("lock182");
    ReleaseLock("lock183");
    ReleaseLock("lock184");
    ReleaseLock("lock185");
    ReleaseLock("lock186");
    ReleaseLock("lock187");
    ReleaseLock("lock188");
    ReleaseLock("lock189");
    ReleaseLock("lock190");
    ReleaseLock("lock191");
    ReleaseLock("lock192");
    ReleaseLock("lock193");
    ReleaseLock("lock194");
    ReleaseLock("lock195");
    ReleaseLock("lock196");
    ReleaseLock("lock197");
    ReleaseLock("lock198");
    ReleaseLock("lock199");
    ReleaseLock("lock200");
    ReleaseLock("lock201");
    ReleaseLock("lock202");
    ReleaseLock("lock203");
    ReleaseLock("lock204");
    ReleaseLock("lock205");
    ReleaseLock("lock206");
    ReleaseLock("lock207");
    ReleaseLock("lock208");
    ReleaseLock("lock209");
    ReleaseLock("lock210");
    ReleaseLock("lock211");
    ReleaseLock("lock212");
    ReleaseLock("lock213");
    ReleaseLock("lock214");
    ReleaseLock("lock215");
    ReleaseLock("lock216");
    ReleaseLock("lock217");
    ReleaseLock("lock218");
    ReleaseLock("lock219");
    ReleaseLock("lock220");
    ReleaseLock("lock221");
    ReleaseLock("lock222");
    ReleaseLock("lock223");
    ReleaseLock("lock224");
    ReleaseLock("lock225");
    ReleaseLock("lock226");
    ReleaseLock("lock227");
    ReleaseLock("lock228");
    ReleaseLock("lock229");
    ReleaseLock("lock230");
    ReleaseLock("lock231");
    ReleaseLock("lock232");
    ReleaseLock("lock233");
    ReleaseLock("lock234");
    ReleaseLock("lock235");
    ReleaseLock("lock236");
    ReleaseLock("lock237");
    ReleaseLock("lock238");
    ReleaseLock("lock239");
    ReleaseLock("lock240");
    ReleaseLock("lock241");
    ReleaseLock("lock242");
    ReleaseLock("lock243");
    ReleaseLock("lock244");
    ReleaseLock("lock245");
    ReleaseLock("lock246");
    ReleaseLock("lock247");
    ReleaseLock("lock248");
    ReleaseLock("lock249");

    AcquireLock("-lock12");
    ReleaseLock("-lock12");
    AcquireLock("lock1000");
    ReleaseLock("lock1000");
    DestroyLock("lock-12");
    DestroyLock("lock1000");

    Print("Stress test ends..\n",-1,-1,-1);

    Exit(0);
}
コード例 #29
0
ファイル: appClerk.c プロジェクト: meldefon/OSsome
void createServerMVs(int numCustomers, int numberOfSenators) {
	int i;
	/*global shared data between the clerks that are used for filing purposes */
	numCustomersLeft = CreateMV("numCustomersLeft", 16, 1);
	bribesEnabled = CreateMV("bribesEnabled", 13, 1);

	customersWithCompletedApps = CreateMV("customersWithCompletedApps", 26, numCustomers);
	customersWithCompletedPics = CreateMV("customersWithCompletedPics", 26, numCustomers);
	passportClerkChecked = CreateMV("passportClerkChecked", 20, numCustomers);
	cashierChecked = CreateMV("cashierChecked", 14, numCustomers);
	gottenPassport = CreateMV("gottenPassport", 14, numCustomers);
	cashReceived = CreateMV("cashReceived", 12, numCustomers);

	appClerkCurrentCustomer = CreateMV("appClerkCurrentCustomer", 23, numCustomers);
	pictureClerkCurrentCustomer = CreateMV("pictureClerkCurrentCustomer", 27, numCustomers);
	passportClerkCurrentCustomer = CreateMV("passportClerkCurrentCustomer", 28, numCustomers);
	cashierCurrentCustomer = CreateMV("cashierCurrentCustomer", 22, numCustomers);

	senatorLock = CreateLock("senatorLock", 11);
	senatorCV = CreateCondition("senatorCV", 9);
	isSenator = CreateMV("isSenator", 9, numCustomers);
	senatorWorking = CreateMV("senatorWorking", 14, 1);
	clerksCanWork = CreateMV("clerksCanWork", 13, 1);

	newCustomerId = CreateMV("newCustomerId", 13, 1);
	newCustomerIdLock = CreateLock("newCustomerIdLock", 17);

	/*Initialize everything*/

	/*
	numCustomersLeft = size;
	bribesEnabled = 1;
	newCustomerId = 0;
	*/
}
コード例 #30
0
int main() {
	loop = TRUE;
	/* Handle Creation Stuff */
	
	/* gettin mah Clerk Index */
	initIndex = CreateMV("PaIn", sizeof("PaIn"), 1, 0x9999);
	initIndexLock = ServerCreateLock("PaInLk", sizeof("PaInLk"), 1);
	
	ServerAcquire(initIndexLock, 0);
	myIndex = GetMV(initIndex, 0);
	SetMV(initIndex, 0, myIndex + 1);
	ServerRelease(initIndexLock, 0);
	
	/* Locks */
	passLock = ServerCreateLock("PaLk", sizeof("PaLk"), NUM_CLERKS);
	senatorLock = ServerCreateLock("SeLk", sizeof("SeLk"), 1);
	customerLock = ServerCreateLock("CuLk", sizeof("CuLk"), 1);
	passLineLock = ServerCreateLock("PaLiLk", sizeof("PaLiLk"), 1);
	clerkWaitLock = ServerCreateLock("ClWaLk", sizeof("ClWaLk"), 1);
	fileLock = ServerCreateLock("FiLk", sizeof("FiLk"), NUM_CUSTOMERS + NUM_SENATORS);
	passMoneyLock = ServerCreateLock("PaMnLk", sizeof("PaMnLk"), 1);
	
	/* CVs */
	clerkWaitCV = ServerCreateCV("ClWaCV", sizeof("ClWaCV"), 1);
	passCV = ServerCreateCV("PaCV", sizeof("PaCV"), NUM_CLERKS);
	regPassLineCV = ServerCreateCV("RgPaCV", sizeof("RgPaCV"), 1);
	privPassLineCV = ServerCreateCV("PrPaCV", sizeof("PrPaCV"), 1);
	
	/* MVs */
	shutdownIndex = CreateMV("shut", sizeof("shut"), 1, 0x9999);
	officeSenatorIndex = CreateMV("OfSe", sizeof("OfSe"), 1, 0x9999);
	officeCustomerIndex = CreateMV("OfCu", sizeof("OfCu"), 1, 0x9999);
	regPassLineLengthIndex = CreateMV("RgPaLn", sizeof("RgPaLn"), 1, 0x9999);
	privPassLineLengthIndex = CreateMV("PrPaLn", sizeof("PrPaLn"), 1, 0x9999);
	numPassWaitIndex = CreateMV("NuPaWa", sizeof("NuPaWa"), 1, 0x9999);
	passDataIndex = CreateMV("PaDa", sizeof("PaDa"), NUM_CLERKS, 0x9999);
	passDataBoolIndex = CreateMV("PaDaBo", sizeof("PaDaBo"), NUM_CLERKS, 0x9999);
	passStateIndex = CreateMV("PaSt", sizeof("PaSt"), NUM_CLERKS, 0x9999);
	fileTypeIndex = CreateMV("FiTp", sizeof("FiTp"), NUM_CUSTOMERS + NUM_SENATORS, 0x9999);
	fileStateIndex = CreateMV("FiSt", sizeof("FiSt"), NUM_CUSTOMERS + NUM_SENATORS, 0x9999);
	passMoneyIndex = CreateMV("PaMn", sizeof("PaMn"), 1, 0x9999);
	
	traceLock = ServerCreateLock("trace", sizeof("trace"), 1);
	
	ServerAcquire(passLock, myIndex);
	SetMV(passStateIndex, myIndex, BUSY);
	ServerRelease(passLock, myIndex);
	
	while(loop == TRUE){
		shutdown = GetMV(shutdownIndex, 0);
		if (shutdown == TRUE) {
			ServerAcquire(traceLock, 0);
			ClerkTrace("Pass", myIndex, 0x00, 0, "Shutting down.\n");
			ServerRelease(traceLock, 0);
			Exit(0);
		}
		ServerAcquire(senatorLock, 0);		/* only one ServerLock, so acquire index 0? */
		ServerAcquire(customerLock, 0);
		
		officeSenator = GetMV(officeSenatorIndex, 0);
		officeCustomer = GetMV(officeCustomerIndex, 0);
		
		if(officeSenator > 0 && officeCustomer > 0){
			ServerRelease(senatorLock, 0);
			ServerRelease(customerLock, 0);

			ServerAcquire(clerkWaitLock, 0);
			ServerWait(clerkWaitCV, 0, clerkWaitLock, 0);
			ServerRelease(clerkWaitLock, 0);
		}
		else{
			ServerRelease(senatorLock, 0);
			ServerRelease(customerLock, 0);	
		}
		/* Check for customers in line */
		ServerAcquire(passLineLock, 0);
		
		privPassLineLength = GetMV(privPassLineLengthIndex, 0);
		regPassLineLength = GetMV(regPassLineLengthIndex, 0);
		if(privPassLineLength > 0){
		/* Decrement line length, set state to AVAIL, signal 1st customer and wait for them */
			privPassLineLength--;
			SetMV(privPassLineLengthIndex, 0, privPassLineLength);
			
			ServerAcquire(senatorLock, 0);
			numPassWait = GetMV(numPassWaitIndex, 0);
			numPassWait++;
			SetMV(numPassWaitIndex, 0, numPassWait);
			ServerRelease(senatorLock, 0);
			
			ServerAcquire(passLock, myIndex);
			SetMV(passStateIndex, myIndex, AVAILABLE);
			ServerSignal(privPassLineCV, 0, passLineLock, 0);
			ServerRelease(passLineLock, 0);
			
			/* wait for customer to signal me */
			ServerWait(passCV, myIndex, passLock, myIndex);
			
			/* customer gave me thier SSN index to check thier file */
			mySSN = GetMV(passDataIndex, myIndex);
			ServerAcquire(fileLock, mySSN);
			/* check customer type */
			
			cType = GetMV(fileTypeIndex, mySSN);
			
			fileState = GetMV(fileStateIndex, mySSN);
			if(fileState == APPPICDONE){
				SetMV(passDataBoolIndex, myIndex, TRUE);
				
				doPassport = TRUE;

				ServerAcquire(traceLock, 0);
				if(cType == CUSTOMER){
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Gives valid certification to Customer.\n");
				}
				else{
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Gives valid certification to Senator.\n");
				}
				ServerRelease(traceLock, 0);
			} else {
				SetMV(passDataBoolIndex, myIndex, FALSE);
				doPassport = FALSE;
				ServerAcquire(traceLock, 0);
				if(cType == CUSTOMER){
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Gives invalid certification to Customer.\n");
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Punishes Customer to wait.\n");		
				}
				else{
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Gives invalid certification to Senator.\n");
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Punishes Senator to wait.\n");
				}
				ServerRelease(traceLock, 0);
			}
			ServerRelease(fileLock, mySSN);

			/* add $500 to passClerk money amount for privileged fee */
			ServerAcquire(passMoneyLock, 0);
			passMoney = GetMV(passMoneyIndex, 0);
			passMoney += 500;
			SetMV(passMoneyIndex, 0, passMoney);
			ServerRelease(passMoneyLock, 0);

			ServerAcquire(traceLock, 0);
			if(cType == CUSTOMER){
				ClerkTrace("Pass", myIndex, "Cust", mySSN, "Accepts $500 from Customer.\n");
				ClerkTrace("Pass", myIndex, "Cust", mySSN, "Informs Customer that the procedure has been completed.\n");
			}
			else{
				ClerkTrace("Pass", myIndex, "Sen", mySSN, "Accepts $500 from Senator.\n");
				ClerkTrace("Pass", myIndex, "Sen", mySSN, "Informs Senator that the produre has been completed.\n");
			}
			ServerRelease(traceLock, 0);

			/* signal customer awake */
			ServerSignal(passCV, myIndex, passLock, myIndex);
			ServerRelease(passLock, myIndex);				/* release clerk lock */

			if(doPassport == TRUE){
				for(i = 0; i < 20; i++){
					/*Yield();	*/
				}

				ServerAcquire(fileLock, mySSN);
				SetMV(fileStateIndex, mySSN, PASSDONE);
				ServerRelease(fileLock, mySSN);
				
				ServerAcquire(traceLock, 0);
				if(cType == CUSTOMER){
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Finished filing Customer's passport.\n");
				}
				else{
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Finished filing Senator's passport.\n");
				}
				ServerRelease(traceLock, 0);
			}
			
			doPassport = FALSE;
			mySSN = 0;
		}

		else if (regPassLineLength > 0){
		/* Decrement line length, set state to AVAIL, signal 1st customer and wait for them */
			regPassLineLength--;
			SetMV(regPassLineLengthIndex, 0, regPassLineLength);
			
			ServerAcquire(senatorLock, 0);
			numPassWait = GetMV(numPassWaitIndex, 0);
			numPassWait++;
			SetMV(numPassWaitIndex, 0, numPassWait);
			ServerRelease(senatorLock, 0);
			
			ServerAcquire(passLock, myIndex);
			SetMV(passStateIndex,  myIndex, AVAILABLE);
			ServerSignal(regPassLineCV, 0, passLineLock, 0);
			ServerRelease(passLineLock, 0);
			ServerWait(passCV, myIndex, passLock, myIndex); /* wait for customer to signal me */

			/* customer gave me thier SSN index to check thier file */
			mySSN = GetMV(passDataIndex, myIndex);
			ServerAcquire(fileLock, mySSN);
			/* check customer type */
			cType = GetMV(fileTypeIndex, mySSN);
			fileState = GetMV(fileStateIndex, mySSN);
			
			if(fileState == APPPICDONE){
				SetMV(passDataBoolIndex, myIndex, TRUE);
				doPassport = TRUE;

				ServerAcquire(traceLock, 0);
				if(cType == CUSTOMER){
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Gives valid certification to Customer.\n");
				}
				else{
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Gives valid certification to Senator.\n");
				}
				ServerRelease(traceLock, 0);
			} else {
				SetMV(passDataBoolIndex, myIndex, FALSE);
				doPassport = FALSE;
				/*Trace("CUSTOMER'S STATE WAS ", fileState);
				Trace("\n", 0x9999);*/
				
				ServerAcquire(traceLock, 0);
				if(cType == CUSTOMER){
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Gives invalid certification to Customer.\n");
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Punishes Customer to wait.\n");	
				}
				else{
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Gives invalid certification to Senator.\n");
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Punishes Senator to wait.\n");
				}
				ServerRelease(traceLock, 0);
			}
			
			ServerAcquire(traceLock, 0);
			if(cType == CUSTOMER){
				ClerkTrace("Pass", myIndex, "Cust", mySSN, "Informs Customer that the procedure has been completed.\n");
			}
			else{
				ClerkTrace("Pass", myIndex, "Sen", mySSN, "Informs Senator that the procedure has been completed.\n");
			}
			ServerRelease(traceLock, 0);

			ServerRelease(fileLock, mySSN);

			ServerSignal(passCV, myIndex, passLock, myIndex); /* signal customer awake */
			ServerRelease(passLock, myIndex);				/* release clerk lock */

			if(doPassport){
				for(i = 0; i < 20; i++){
					/*Yield();*/
				}

				ServerAcquire(fileLock, mySSN);
				SetMV(fileStateIndex, mySSN, PASSDONE);
				ServerRelease(fileLock, mySSN);
				
				ServerAcquire(traceLock, 0);
				if(cType == CUSTOMER){
					ClerkTrace("Pass", myIndex, "Cust", mySSN, "Finished filing Customer's passport.\n");
				}
				else{
					ClerkTrace("Pass", myIndex, "Sen", mySSN, "Finished filing Senator's passport.\n");
				}
				ServerRelease(traceLock, 0);
			}
			doPassport = FALSE;
			mySSN = 0;
		}
		else{
			/* No one in line...take a break */
			ServerRelease(passLineLock, 0);
			ServerAcquire(passLock, myIndex);
			
			ServerAcquire(traceLock, 0);
			ClerkTrace("Pass", myIndex, 0x00, 0, "Goin on break.\n");
			ServerRelease(traceLock, 0);
			
			SetMV(passStateIndex, myIndex, BREAK);
			ServerWait(passCV, myIndex, passLock, myIndex);
			
			ServerAcquire(traceLock, 0);
			ClerkTrace("Pass", myIndex, 0x00, 0, "Returning from break.\n");
			ServerRelease(traceLock, 0);

			ServerRelease(passLock, myIndex);
		}
	}
}