예제 #1
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);
}
예제 #2
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);
}
예제 #3
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);
}
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);
}