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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}