コード例 #1
0
int main()
{

	lock = CreateLock("lock");
	lock2 = CreateLock("lock2");

	cv1 = CreateCV("cv1");
	cv2=CreateCV("cv2");

	AcquireLock("lock");
	
	SignalCV("lock","cv1");
	
	Print("Client 2 is going to wait...",-1,-1,-1);
	
	WaitCV("lock","cv2");

	for (i=0; i<9; i++)
		Print("\n",-1,-1,-1);
	
	Print("Client 2 is now out of wait...",-1,-1,-1);

	ReleaseLock("lock");

	Exit(0);

}
コード例 #2
0
ファイル: passporttest5.c プロジェクト: anjaliahuja/csci-350
void initClerksData() {
  int i;
  char* name;

  int lineCV;
  int bribeLineCV;
  int senatorCV;

  for (i = 0; i < NUM_APPCLERKS; i++) {
    AppClerks[i].name = "appclerk_" + i;
    AppClerks[i].id = i;
    AppClerks[i].state = 0;
    name = numString("appclerk_lock_", sizeof("appclerk_lock_"), i);
    AppClerks[i].lock = CreateLock(name, sizeof(name));
    name = numString("appclerk_cv_", sizeof("appclerk_lock_"), i);
    AppClerks[i].cv = CreateCV(name, sizeof(name));
    name = numString("appclerk_lineCV_", sizeof("appclerk_lock_"), i);
    AppClerks[i].lineCV = CreateCV(name, sizeof(name));
    name = numString("appclerk_bribeLineCV_", sizeof("appclerk_lock_"), i);
    AppClerks[i].bribeLineCV = CreateCV(name, sizeof(name));
    name = numString("appclerk_SenatorCV_", sizeof("appclerk_lock_"), i);
    AppClerks[i].senatorCV = CreateCV(name, sizeof(name));

    queue_init(&AppClerks[i].line);
    queue_init(&AppClerks[i].bribeLine);
    AppClerks[i].likePicture = false;
  }
}
コード例 #3
0
ファイル: airportsim.c プロジェクト: kyuhyunc/csci350
void initAirlines() {
#define a Airlines[i]
	int i, j;
	for (i = 0; i < NUM_AIRLINES; ++i) {
		a._lock = CreateLock(concatNumToString("airline_lock_", sizeof("airline_lock_"), i), 14);
    	a._execLineLock = CreateLock(concatNumToString("airline_exec_lock_", sizeof("airline_exec_lock_"), i), 19);
    	a._execLineCV = CreateCV(concatNumToString("airline_execLineCV_", sizeof("airline_execLineCV_"), i), 20);
    	a._boardLoungeCV = CreateCV(concatNumToString("airline_boardLoungeCV_", sizeof("airline_boardLoungeCV_"), i), 23);
    	a._cisLineLock = CreateLock(concatNumToString("airline_CIS_lock_", sizeof("airline_CIS_lock_"), i), 18);
/*    	for (j = 0; j < NUM_CIS_PER_AIRLINE; ++j) {*/
    		initCIS(i);
/*    	}*/
        for (j = 0; j < NUM_PASSENGERS; j++) {
            a._execQueue._array[j] = -1;
        }
        a._execQueue._front = -1;
        a._execQueue._rear = -1;

  		/* Stats */
/*    	a._numExpectedPassengers = 0;*/
    	a._numCheckedinPassengers = 0;
    	a._numReadyPassengers = 0;
/*    	a._numExpectedBaggages = 0;*/
    	a._numLoadedBaggages = 0;
/*    	a._bagCount = 0;*/
/*    	a._weightCount = 0;*/
    	/* Shutdown */
    	a._numOnBreakCIS = 0;
    	a._boarded = false;
    	a._allPassengersCheckedIn = false;
    	a._CISclosed = false;
	}
#undef a
}
コード例 #4
0
ファイル: tc.c プロジェクト: achinksinghal/CSCI_402
/*
 * this will initialize the locks and condition variables that we created for each queues, manager, ticker clerks, concession clerks, tikcet takers, customers
 * */
void initializeAllLocks(int debugId)
{
	int i,j;
	i=0, j=0; /*char *lockName;*/

	for(i=(tc_number * 2) ; i <= (tc_number * 2) + 1; i++)
	{ /*we start with the customers and create locks and CVs for them*/
		j=0;
		{
			custLock[i][j] = mtCb.custGrp[i].cust[j].name;
			CreateLock(mtCb.custGrp[i].cust[j].name);
			/*Print("tc lock created custlock=%s grp=%d cust=%d\n", custLock[i][j], i, j );*/
			
			custCondVar[i][j]= mtCb.custGrp[i].cust[j].name;
			CreateCV(mtCb.custGrp[i].cust[j].name);
			/*Print("tc lock created condvar=%s grp=%d cust=%d\n", custCondVar[i][j], i, j );*/
		}
	}

	{ /*lock and CV for ticket clerk*/
		tcLock[tc_number] = mtCb.tc[tc_number].name;
		CreateLock(mtCb.tc[tc_number].name);
		/*Print("tc lock created tclock=%s tc=%d \n", tcLock[tc_number], tc_number, -1 );*/
		
		tcCondVar[tc_number] = mtCb.tc[tc_number].name;
		CreateCV(mtCb.tc[tc_number].name);
		/*Print("tc lock created condvar=%s tc=%d \n", tcCondVar[tc_number], tc_number, -1 );*/
	}
}
コード例 #5
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");
	
}
コード例 #6
0
ファイル: locktest.c プロジェクト: jamestlynch/Nachos
int main() 
{
    LockIndex1= CreateLock("Lock1", 5);
    Write("Lock 1 created\n", sizeof("Lock 1 created\n"), 1);
    LockIndex2 = CreateLock("Lock2", 5);
    Write("Lock 2 created\n", sizeof("Lock 2 created\n"), 1);
    LockIndex3 = CreateLock("Lock3", 5);
    Write("Lock 3 created\n", sizeof("Lock 3 created\n"), 1);
    LockIndex4 = CreateLock("Lock4", 5);
    Write("Lock 4 created\n", sizeof("Lock 4 created\n"), 1);
    CVIndex1 = CreateCV("CV1", 3);
    Write("CV 1 created\n", sizeof("CV 1 created\n"), 1);
    CVIndex2 = CreateCV("CV2", 3);
    Write("CV 2 created\n", sizeof("CV 2 created\n"), 1);
    CVIndex3 = CreateCV("CV3", 3);
    Write("CV 3 created\n", sizeof("CV 3 created\n"), 1);
    CVIndex4 = CreateCV("CV4", 3);
    Write("CV 4 created\n", sizeof("CV 4 created\n"), 1);

    /*BoundsErrorCheck_Test();
     passingVars_Test();*/

    test6();
    /*test2();
    


    /*test2();
    test3();
    test4();
    test5();*/
    /*test6();*/

/*
    int lock1;

    /*BoundsErrorCheck_Test();
    int lock1, lock2, lock3, lock4;
    lock1= CreateLock("abc", 3);
    /*lock2= CreateLock("def", 3);
    lock3= CreateLock("ghi", 3);
    lock4= CreateLock("jkl", 3);*/

    /*Fork("thread1", 7, unsigned int vFuncAddr);
    Fork("thread2", 7, unsigned int vFuncAddr);
    Fork("thread3", 7, unsigned int vFuncAddr);


     /*CreateLock_Test(); */
     /*Acquire_Test();*/
     /*Release_Test();*/
     /*DestroyLock_Test();*/


	/* Multiple threads test */
}
コード例 #7
0
ファイル: locktest.c プロジェクト: jamestlynch/Nachos
void t3_t1(){
    indexcheck1=CreateCV("def", 1);
    indexcheck2=DestroyCV(indexcheck1+100);
    indexcheck3= CreateCV("abc", -1);
    indexcheck4=DestroyCV(-100);
    if (indexcheck1==-1 && indexcheck2==-1 && indexcheck3==-1 && indexcheck4==-1){
        Write("passed: create/destroyCV validates input\n", sizeof("passed: create/destroyCV validates input\n"), 1);
    }
    else{
        Write("failed: create/destroyCV validates input\n", sizeof("failed: create/destroyCV validates input\n"), 1);
    }
}
コード例 #8
0
ファイル: testfiles.c プロジェクト: aitbayev/nachos-csci402-1
	/* Create a lot of cv's to be used in later tests */
  void create_Many_CVs_Test(){
		Write("Testing Create CV 9 more times\n", sizeof("Testing Create CV 9 more times\n"), ConsoleOutput);
		cv_2 = CreateCV();
		cv_3 = CreateCV();
		cv_4 = CreateCV();
		cv_5 = CreateCV();
		cv_6 = CreateCV();
		cv_7 = CreateCV();
		cv_8 = CreateCV();
		cv_9 = CreateCV();
		cv_10 = CreateCV();
	}
コード例 #9
0
int main()
{

	lock = CreateLock("lock");
	cv2 = CreateCV("cv2");
	
	AcquireLock("lock");

	SignalCV("lock","cv2");

	Print("Client 3 will now destroy CV...",-1,-1,-1);
	
	DestroyCV("cv2");
	
	for (i=0; i<9; i++)
		Print("\n",-1,-1,-1);


	ReleaseLock("lock");

	AcquireLock("lock");	
	
	WaitCV("lock","cv2");
	
	Print("Client 3: This prints as CV has been destroyed...",-1,-1,-1);

	ReleaseLock("lock");

	Exit(0);

}
コード例 #10
0
void main()
{
	lck = CreateLock("lock1");
	cv = CreateCV("cv1");
	Print("\nDistCVTest1_1: Created Lock is %d and CV is %d\n", lck, cv, -1);
	

	AcquireLock("lock1");

	
	Print("Client 1: About to go on wait...\n", -1, -1, -1);

	
	WaitCV("lock1","cv1");

	Print("Client 1: Now out of wait...\n", -1, -1, -1);

	for (num=0; num<10; num++)
		Print("\n",-1,-1,-1);
	
	Print("Client 1: About to signal Client 2\n", -1, -1, -1);
	
	SignalCV("lock1","cv1");

	ReleaseLock("lock1");
	AcquireLock("lock1");


	ReleaseLock("lock1");
	
	Exit(0);
	
	
}
コード例 #11
0
void main()
{
	int lck1,cv1;
	
	Print("\nTC1_1 :: Checking Correct Working of Creating & Deleting of Locks and CV.\n",1,1,1);

	lck1 = CreateLock("lock1", 5);			
	Print("\nTC1_1 :: Lock name 'lock1' Created. The Index is '%d'.\n",lck1,1,1);
	
	cv1 = CreateCV("cv1", 3);				
	Print("\nTC1_1 :: CV name 'cv1' Created. The Index is '%d'.\n",cv1,1,1);
	
	Acquire(lck1);							
	
	Print("\nTC1_1 :: Going on wait on 'cv1' using 'lock1'. Now run the 'tc1_2' file.\n",1,1,1);
	Wait(cv1,lck1);
	Print("\nTC1_1 :: Have been signalled on 'cv1' using 'lock1'.\n",1,1,1);

	Release(lck1);							

	DeleteCV(cv1);						

	DeleteLock(lck1);	
	
	Print("\nTC1_1 :: Reached end.\n",lck1,1,1);
	Exit(0);
}
コード例 #12
0
void main()
{
	int lck1,cv1=-1,lck2;
	
	Print("\nTC5_1 :: Checking Working of Wait and Signal. \n",1,1,1);

	lck1 = CreateLock("lock1", 5);			
	Print("\nTC5_1 :: Lock name 'lock1' Created. The Index is '%d'.\n",lck1,1,1);

	Acquire(lck1);							
	
	Print("\nTC5_1 :: Going on wait on 'cv1' that is not created using 'lock1'. Will not go on wait.\n",1,1,1);
	Wait(cv1,lck1);
	Print("\nERROR - TC5_1 :: Could not go on wait on 'cv1' using 'lock1'.\n",1,1,1);

	cv1 = CreateCV("cv1", 3);				
	Print("\nTC5_1 :: CV name 'cv1' Created. The Index is '%d'.\n",cv1,1,1);
	
	Print("\nTC5_1 :: Going on wait on 'cv1' that is now created using 'lock1'. Now run the 'tc5_2' file.\n",1,1,1);
	Wait(cv1,lck1);
	Print("\nTC5_1 :: Have been signalled on 'cv1' using 'lock1'.\n",1,1,1);

	Release(lck1);							

	DeleteCV(cv1);						

	DeleteLock(lck1);						
	
	Print("\nTC5_1 :: Reached end.\n",lck1,1,1);
	Exit(0);
}
コード例 #13
0
void main()
{
	int lck1,cv1,lck2;
	
	Print("\nTC6_1 :: Checking Working of Wait and Signal. \n",1,1,1);

	lck1 = CreateLock("lock1", 5);			
	Print("\nTC6_1 :: Lock name 'lock1' Created. The Index is '%d'.\n",lck1,1,1);

	cv1 = CreateCV("cv1", 3);				
	Print("\nTC6_1 :: CV name 'cv1' Created. The Index is '%d'.\n",cv1,1,1);
	
	Acquire(lck1);												

	Print("\nTC6_1 :: Going on wait on 'cv1' using 'lock1' that is the correct lock (First Waiter). Will go on wait. Now run the 'tc6_2' file. \n",1,1,1);
	Wait(cv1,lck1);
	Print("\nTC6_1 :: Have been Signalled on 'cv1' using 'lock2'.\n",1,1,1);

	Release(lck1);							

	DeleteCV(cv1);						

	DeleteLock(lck1);						

	Print("\nTC6_1 :: Reached end.\n",lck1,1,1);
	Exit(0);
}
コード例 #14
0
void main()
{
	Print("\n tcase7_2: THIS FILE DOES NOT GO ON WAIT AS THE LOCK IS DIFFERENT. \n",1,1,1);

	CreateLock("lock2");
/*	Print("\n tcase7_2: lock2 Has Been Created. \n",1,1,1); */

	CreateCV("cv1");
/*	Print("\n tcase7_2: cv1 Has Been Created. \n",1,1,1); */
	
	Acquire("lock2");
/*	Print("\n tcase7_2: lock 2 Has Been Acquired. \n",1,1,1); */

	Print("\n tcase7_2: Going on wait on 'cv1' using 'lock2' that is not the correct lock for that CV (Not the First Waiter). \n",1,1,1);
	Print("\n Will Not go on wait. \n",1,1,1);

	Wait("cv1","lock2");

	Print("\n ERROR - tcase7_2: Could not be Signalled AS DID NOT GO ON WAIT on 'cv1' using 'lock2'.\n",1,1,1);

	Release("lock2");
/*	Print("\n tcase7_2: lock 2 Has Been Released. \n",1,1,1); */

/*	Print("\n tcase7_2: Requesting to Delete 'cv1', but will delete only if it is the last userprog deleting it.\n",1,1,1);
	DeleteCV("cv1");

	Print("\n tcase7_2: Requesting to Delete 'lock2', but will delete only if it is the last userprog deleting it.\n",1,1,1);
	DeleteLock("lock2");
*/

	Print("\n tcase7_2: Reached end. Now run the 'tc7_3' file.\n",1,1,1);
	Exit(0);
}
コード例 #15
0
void main()
{
    int lck1,cv1;

    Print("\nTC1_2 :: Checking Correct Working of Creating & Deleting of Locks and CV.\n",1,1,1);

    lck1 = CreateLock("lock1", 5);
    Print("\nTC1_2 :: Lock name 'lock1' Created. The Index is '%d'.\n",lck1,1,1);

    cv1 = CreateCV("cv1", 3);
    Print("\nTC1_2 :: CV name 'cv1' Created. The Index is '%d'.\n",cv1,1,1);

    Acquire(lck1);

    Print("\nTC1_2 :: Going to signal on 'cv1'. The waiter on 'cv1' will be woken up.\n",1,1,1);
    Signal(cv1,lck1);


    Release(lck1);

    DeleteCV(cv1);

    DeleteLock(lck1);

    Print("\nTC1_2 :: Reached end.\n",lck1,1,1);
    Exit(0);
}
コード例 #16
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);
}
コード例 #17
0
void main()
{
    lck = CreateLock("lock1");
    cv = CreateCV("cv1");
    Print("Client 2: Created Lock is %d and CV is %d\n", lck, cv, -1);

    AcquireLock("lock1");


    Print("Client 2: About to signal Client 1\n", -1, -1, -1);

    SignalCV("lock1","cv1");

    Print("Client 2: About to go on wait...\n", -1, -1, -1);


    WaitCV("lock1","cv1");
    for (i=0; i<10; i++)
        Print("\n",-1,-1,-1);

    Print("Client 2: Now out of wait...\n", -1, -1, -1);
    ReleaseLock("lock1");

    Exit(0);
}
コード例 #18
0
void main()
{
	Print("\n tcase7_1: Checking Working of Wait and Signal - THIS FILE GOES ON WAIT SUCCESSFULLY. \n",1,1,1);

	CreateLock("lock1");
/*	Print("\n tcase7_1: lock1 Has Been Created. \n",1,1,1); */

	CreateCV("cv1");
/*	Print("\n tcase7_1: cv1 Has Been Created. \n",1,1,1); */
	
	Acquire("lock1");
/*	Print("\n tcase7_1: lock 1 Has Been Acquired. \n",1,1,1); */

	Print("\n tcase7_1: Going on wait on 'cv1' using 'lock1' that is the correct lock (First Waiter). \n",1,1,1);
	Print("\n Will go on wait. Now run the 'tc7_2' file. \n",1,1,1);

	Wait("cv1","lock1");

	Print("\n tcase7_1: Have been Signalled on 'cv1' using 'lock1'.\n",1,1,1);

	Release("lock1");
/*	Print("\n tcase7_1: lock 1 Has Been Released. \n",1,1,1); */

/*	Print("\n tcase7_1: Requesting to Delete 'cv1', but will delete only if it is the last userprog deleting it.\n",1,1,1);
	DeleteCV("cv1");

	Print("\n tcase7_1: Requesting to Delete 'lock1', but will delete only if it is the last userprog deleting it.\n",1,1,1);
	DeleteLock("lock1");
*/

	Exit(0);
}
コード例 #19
0
ファイル: lock_cv_test4.c プロジェクト: anjaliahuja/csci-350
int main() {
    lock = CreateLock("lock", 4);
    cv = CreateCV("cv", 2);
    Write("Test 4 broadcasts all locks\n", sizeof("Test 4 broadcasts all locks\n"), ConsoleOutput);
  Acquire(lock);
  Broadcast(lock, cv);
  Release(lock);
}
コード例 #20
0
ファイル: test4.c プロジェクト: yoshE/Operating_Systems
void main()
 {
	a = CreateLock("lock1",5);
	b = CreateCV("cond1",5);
	count =0;
	Fork(thread1);
	Fork(thread2);
	Fork(thread3);
 }
コード例 #21
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);
}
コード例 #22
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);
}
コード例 #23
0
ファイル: airportsim.c プロジェクト: kyuhyunc/csci350
/*
	Initializes all CIS within an airline
*/
void initCIS(int airline) { 
#define cis Airlines[airline]._cis[i]
	int i;
    int j;
	NumActiveCIS = 0;
	for (i = 0; i < NUM_CIS_PER_AIRLINE; i++) {
		cis._lock = CreateLock(concatNumToString("CIS_lock_", sizeof("CIS_lock_"), i), 10);
    	cis._lineCV = CreateCV(concatNumToString("CIS_lineCV_", sizeof("CIS_lineCV_"), i), 12);
    	cis._commCV = CreateCV(concatNumToString("CIS_comCV_", sizeof("CIS_comCV_"), i), 11);;
    	cis._lineSize = 0;
    	cis._state = BUSY;
    	cis._passCount = 0;
    	cis._bagCount = 0;
    	cis._weightCount = 0;
    	cis._currentPassenger = -1;
    	cis._airline = airline;
    	cis._done = false;
	}
#undef cis
}
コード例 #24
0
ファイル: airportsim.c プロジェクト: kyuhyunc/csci350
void initLiaisons() {
/*Printf0("got into initLiaisons\n", sizeof("got into initLiaisons\n"));*/
	int i;
	int j;
	NumActiveLiaisons = 0;
	for (i = 0; i < NUM_LIASONS; i++) { 
		Liaisons[i]._lock = CreateLock(concatNumToString("liaison_lock_", sizeof("liaison_lock_"), i), 14);
		Liaisons[i]._lineCV = CreateCV(concatNumToString("liaison_lineCV_", sizeof("liaison_lineCV_"), i), 16);
		Liaisons[i]._commCV = CreateCV(concatNumToString("liaison_commCV_", sizeof("liaison_commCV_"), i), 16);
/*		Liaisons[i]._lock = CreateLock("llinelock", sizeof("llinelock"));
		Liaisons[i]._lineCV = CreateCV("llinecv", sizeof("llinecv"));
		Liaisons[i]._commCV = CreateCV("lcommcv", sizeof("lcommcv"));*/
		for (j = 0; j < NUM_AIRLINES; j++) {
			Liaisons[i]._passCount[j] = 0;
			Liaisons[i]._bagCount[j] = 0;
		}
		Liaisons[i]._currentPassenger = -1;
		Liaisons[i]._state = BUSY;
		Liaisons[i]._lineSize = 0;
	}
}
コード例 #25
0
ファイル: cc.c プロジェクト: achinksinghal/CSCI_402
/*
 * We'll setup all the queues that
 * need to be part of simulation
 * */
void initializeAllQueues(int debugId )
{
	/*setting up requisite number of concession clerk queues*/
	mtCb.queue[CC_QUEUE][cc_number].queueId = cc_number;
	mtCb.queue[CC_QUEUE][cc_number].queueType = CC_QUEUE;
	initializeQueue(debugId, &mtCb.queue[CC_QUEUE][cc_number]);
	queueLock[CC_QUEUE][cc_number] = mtCb.queue[CC_QUEUE][cc_number].name;
	CreateLock(mtCb.queue[CC_QUEUE][cc_number].name);
	queueCondVar[CC_QUEUE][cc_number] = mtCb.queue[CC_QUEUE][cc_number].name;
	CreateCV(mtCb.queue[CC_QUEUE][cc_number].name);
	addAddressToQueue(debugId, cc_number, CC_QUEUE, cc_number);
}
コード例 #26
0
ファイル: cvtest3.c プロジェクト: achinksinghal/CSCI_402
int main()
{
	i=CreateLock("Lock 0");
	Print("Lock_%d created...\n",i,-1,-1);
	
	for(loop = 0; loop < 1000 ;loop++)
		{
			j=CreateCV("CV j");
			j2=CreateCV("CV j2");

			AcquireLock(i);
			WaitCV(i,j2+1);
			Print("This doesnt print after we get errors for going out of threads..\n",-1,-1,-1);
			Fork(test,"Fork 1");
			
			WaitCV(i,j);
			Print("main is now awake\n",-1,-1,-1);
			DestroyCV(j);/*Only one of the locks is always deleted*/
		}

}
コード例 #27
0
ファイル: airportsim.c プロジェクト: kyuhyunc/csci350
void initSecurityInspectors() {
	int i;
	NumActiveSecurityInspectors = 0;
	#define inspector SecurityInspectors[i]
	for (i = 0; i < NUM_SCREENING_OFFICERS; ++i) {
		inspector._id = i;
	    inspector._rtnPassSize = 0;
	    inspector._state = BUSY;
/*		inspector._state = AVAIL; /* SWITCH BACK LATER */
	    inspector._lock = CreateLock(concatNumToString("inspector_lock_", sizeof("inspector_lock_"), i), 14);
	    inspector._commCV = CreateCV(concatNumToString("_commCV", sizeof("_commCV"), i), 20);
	    inspector._rtnPassCV = CreateCV(concatNumToString("_rtnPassCV", sizeof("_rtnPassCV"), i), 20);
	    inspector._newPassCV = CreateCV(concatNumToString("_newPassCV", sizeof("_newPassCV"), i), 20);
	    inspector._rtnPassenger = -1;
	    inspector._newPassenger = -1;
/*Printf1("SI %d has _newPassenger", sizeof("SI %d has _newPassneger"), i);
Printf1("%d\n", sizeof("%d\n"), inspector._newPassenger);*/
	    inspector._passCount = 0;
	}
	#undef inspector
}
コード例 #28
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);

}
コード例 #29
0
ファイル: test1.c プロジェクト: abhishektayal/OS
void main()
{
	count =0;

	a = CreateLock("lock1",5);
	b = CreateCV("cond1",5);

	Fork(thread1);
	Fork(thread2);
	Yield();
	Yield();
	Yield();
}
コード例 #30
0
ファイル: test8.c プロジェクト: abhishektayal/OS
void main()
 {

	a = CreateLock("lock1",5);
	b = CreateCV("cond1",5);

	count =0;

	for( j=0;j<105;j++)
	{
		Fork(thread1);
	}
}