int main() { Write("Creating test locks and CVs, should be successful\n", 50, ConsoleOutput); lock1 = CreateLock("Lock1", 5, 0); lock2 = CreateLock("Lock2", 5, 0); cond1 = CreateCondition("Condition1", 10, 0); cond2 = CreateCondition("Condition2", 10, 0); lock3 = CreateLock("Lock3", 5, 0); lock4 = CreateLock("Lock4", 5, 0); cond3 = CreateCondition("Condition3", 10, 0); cond4 = CreateCondition("Condition4", 10, 0); condToBeDestroyed = CreateCondition("condToBeDestroyed", 17, 0); theLockThatDoesntExist = lock1+10; theCondThatDoesntExist = cond1+10; Write("Destroying CV, should see both successful and unsuccesful attempts.\n", 68, ConsoleOutput); Write("Destroying condToBeDestroyed\n", 29, ConsoleOutput); DestroyCondition(condToBeDestroyed); Write("Destroying theCondThatDoesntExist\n", 34, ConsoleOutput); DestroyCondition(theCondThatDoesntExist); Write("Waiting theCondThatDoesntExist\n", 32, ConsoleOutput); Acquire(lock1); Wait(lock1, theCondThatDoesntExist); Write("Signaling theCondThatDoesntExist\n", 34, ConsoleOutput); Acquire(lock1); Signal(lock1, theCondThatDoesntExist); Release(lock1); Write("Broadcasting theCondThatDoesntExist\n", 36, ConsoleOutput); Broadcast(lock1,theCondThatDoesntExist); Write("Finshing condInit\n", 18, ConsoleOutput); Exit(0); }
int main() { char* nameCV = "CV"; int CV = 0, i = 0; int returnValue = 0; Printx("Owner process is creating a new CV\n",37,1); CV = CreateCondition(nameCV,2); if (CV == -1){ Printx("Owner process not able to create CV\n",38,1); } Printx("Owner process is destroying the CV\n",37,1); returnValue = DestroyCondition(CV); if (returnValue == -1){ Printx("Owner not able to destroy CV\n",31,1); } Printx("Owner process is attempting to destroy the CV again\n",54,1); returnValue = DestroyCondition(CV); if (returnValue == -1){ Printx("Owner not able to destroy CV\n",31,1); } Exit(0); /* not reached */ }
/* tests destroy cv syscall when other threads waiting*/ void CVTest3() { /* all of the error checking was copy and pasted, so it's already been checked by previous tests */ int i; PrintF("\nTest 3 - Testing delete when other threads waiting\n", sizeof("\nTest 3 - Testing delete when other threads waiting\n"), 0, 0); /*showed delete works normally in test 1 - now show it works when cv has to be deleted from wait */ Acquire(myLock1); Fork(threadTest3); Fork(threadTest3); Release(myLock1); for (i = 0; i < 100; i++) /*extra yields make sure threads get a chance to get going before trying to delete */ Yield(); DestroyCondition(myCV1); PrintF("Trying to destroy in test 3\n", sizeof("Trying to destroy in test 3\n"), 0, 0); Acquire(myLock1); Broadcast(myCV1, myLock1); Release(myLock1); /*now prints an error because lock has now been deleted */ for (i = 0 ;i < 100; i++) Yield(); PrintF("Now an error is printed because CV has been deleted: \n", sizeof("Now an error is printed because CV has been deleted: \n"), 0, 0); Wait(myCV1, myLock1); PrintF("\n", 1, 0, 0); }
void signal_waiter_destroy(){ int returnValue = 0, i = 0; /* Yield to allow other thread to acquire the lock and wait on the CV first. */ for(i = 0; i < 100; i++){ Yield(); } Printx("Thread 2 is destroying the lock\n",34,1); returnValue = DestroyLock(lock); if(returnValue == -1){ Printx("Thread 2 not able to destroy the lock\n",38,1); } Printx("Thread 2 is signalling the waiter using a destroyed lock\n",59,1); returnValue = Signal(CV, lock); if(returnValue == -1){ Printx("Thread 2 not able to signal on the CV\n",38,1); } Printx("Thread 2 is destroying the CV\n",32,1); returnValue = DestroyCondition(CV); if(returnValue == -1){ Printx("Thread 2 not able to destroy the CV\n",38,1); } Printx("Thread 2 is signalling the waiter using a destroyed CV\n",57,1); returnValue = Signal(CV, lock); if(returnValue == -1){ Printx("Thread 2 not able to signal on the CV\n",40,1); } Exit(0); }
void Lockdestroytest() { int lockd,cvd; lockd=CreateLock("lockd",5); DestroyLock(lockd);/* you cannot destroy as client 1 is also using this lock*/ cvd=CreateCondition("cvd",3); DestroyCondition(cvd); }
int main() { Write("Creating test locks and CVs, should be successful\n", 50, ConsoleOutput); lock1 = CreateLock("Lock1", 5, 0); lock2 = CreateLock("Lock2", 5, 0); cond1 = CreateCondition("Condition1", 10, 0); cond2 = CreateCondition("Condition2", 10, 0); lock3 = CreateLock("Lock3", 5, 0); lock4 = CreateLock("Lock4", 5, 0); cond3 = CreateCondition("Condition3", 10, 0); cond4 = CreateCondition("Condition4", 10, 0); condToBeDestroyed = CreateCondition("condToBeDestroyed", 17, 0); theLockThatDoesntExist = lock1+10; theCondThatDoesntExist = cond1+10; PrintNl(); Write("Testing invalid actions for conds\n", 34, ConsoleOutput); Write("Waiting with invalid lock and valid condition, should give error\n", 65, ConsoleOutput); Wait(theLockThatDoesntExist, cond1); Write("Waiting with valid lock and invalid condition, should give error\n", 65, ConsoleOutput); Wait(lock1, theCondThatDoesntExist); Write("Signaling theCondThatDoesntExist, should give error\n", 52, ConsoleOutput); Signal(lock1, theCondThatDoesntExist); Write("Destroying theCondThatDoesntExist, should give error\n", 53, ConsoleOutput); DestroyCondition(theCondThatDoesntExist); Write("Destroying condToBeDestroyed, should be successful\n", 51, ConsoleOutput); DestroyCondition(condToBeDestroyed); Write("Signaling condToBeDestroyed, should give error\n", 47, ConsoleOutput); Signal(lock1, condToBeDestroyed); Write("Broadcasting condToBeDestroyed, should give error\n", 50, ConsoleOutput); Broadcast(lock1, condToBeDestroyed); Write("Destroying condToBeDestroyed, should give error\n", 48, ConsoleOutput); DestroyCondition(condToBeDestroyed); Write("Waiting before acquring, should give error\n", 43, ConsoleOutput); Wait(lock1, cond1); Write("Signaling before acquring, should give error\n", 45, ConsoleOutput); Signal(lock1, cond1); Write("Broadcasting before acquring, should give error\n", 48, ConsoleOutput); Broadcast(lock1, cond1); Write("Finshing condServerInitTest\n", 28, ConsoleOutput); Exit(0); }
void main() { unsigned int i; int conditionNum; conditionNum=CreateCondition("condition",9); DestroyCondition(conditionNum); Exit(0); }
void lockcvdestroytest() { int lockd,cvd; lockd=CreateLock("lockd",5); cvd=CreateCondition("cvd",3); DestroyLock(lockd); DestroyCondition(cvd); }
int main() { /*Create lock, CV*/ int i,j,total; int lockID, cvID; lockID = CreateLock("testLock",8); cvID = CreateCondition("testCV",6); /*Get into critical section*/ Acquire(lockID); Write("Sector 1...\n",12,ConsoleOutput); /*Do some work*/ for(i = 0;i<LEN;i++){ for(j = 0;j<LEN;j++){ total += i*j; /*Just to keep the thread occupied*/ } } /*Signal and then wait for another signal*/ Signal(cvID,lockID); Wait(cvID,lockID); Write("Sector 2...\n",12,ConsoleOutput); /*Do some work*/ for(i = 0;i<LEN;i++){ for(j = 0;j<LEN;j++){ total += i*j; /*Just to keep the thread occupied*/ } } /*Signal. Even though the last thread will be signalling no one, this is part of the test * to allow all threads to finish*/ Signal(cvID,lockID); /*Release*/ Release(lockID); Write("Out of critical section\n",24,ConsoleOutput); /*Destroy the lock, cv (really, set its toBeDestroyed bit to true)*/ DestroyLock(lockID); DestroyCondition(cvID); /*Send a result to print*/ Exit(total); }
int main() { Write("\nTESTING: TRYING TO DESTROY A CONDITION VARUIABLE WHEN STILL THREADS ARE WAIITNG IN THE WAIT QUEUE",98,1); l1=CreateLock(); cv1=CreateCondition(); Fork(fun1); Yield(); Yield(); Yield(); DestroyCondition(cv1); Exit(0); }
void positivetestcase1() { int L1,cv1; L1=CreateLock("USERLOCK",8);/*LOCK is created*/ cv1=CreateCondition("USERCV",6);/*CV is created*/ DestroyLock(L1);/*Lock is destroyed*/ DestroyCondition(cv1);/*CV is destroyed*/ }
void lockcvdestroytest() { int lockd,cvd; lockd=CreateLock("lockd",5); cvd=CreateCondition("cvd",3); Print("Please press any number after you run client 2, for successfull deletion of the lock and cv\n"); Scan("%d"); DestroyLock(lockd); DestroyCondition(cvd); }
void negativecase2() { int Lock9=-1; int Lock1; int CV1; int CV9=-1; DestroyLock(-1);/*InValid Lock Index*/ DestroyLock(3000);/*InValid Lock Index*/ DestroyLock(Lock9);/*Cannot delete a lock whic is not created */ Lock1= CreateLock("USERLOCK",8); Acquire(Lock1); DestroyLock(Lock1);/*trying to delete a lock whose usage counter is non zero*/ DestroyCondition(-1);/*InValid CV Index*/ DestroyCondition(3000);/*InValid CV Index*/ DestroyCondition(CV9);/*Cannot delete a CV which is not created */ Release(Lock1); DestroyLock(Lock1); DestroyLock(Lock1);/* try to delete a lock which is already deleted*/ CV1=CreateCondition("cv1",3); DestroyCondition(CV1); DestroyCondition(CV1);/*trying to delete a cv which is already deleted*/ }
int main(){ lockid = CreateLock("LOCK1", 5); initlock = CreateLock("LOCK2", 5); condid = CreateCondition("COND1", 5); initcond = CreateCondition("COND2", 5); Write( "test4\n", 6, ConsoleOutput ); Acquire(initlock); Fork(waiter); Wait(initcond, initlock); Fork(signaller); while(i != 2){ Wait(initcond, initlock); } Release(initlock); DestroyLock(lockid); DestroyLock(initlock); DestroyCondition(condid); DestroyCondition(initcond); Exit(0); }
int pthread_cond_destroy (pthread_cond_t * cond) { __CONDITION* pCond = NULL; if(NULL == cond) { return EINVAL; } if(NULL == (*cond)->cond) { return EINVAL; } DestroyCondition((HANDLE)((*cond)->cond)); KMemFree((*cond),KMEM_SIZE_TYPE_ANY,0); return S_OK; }
int main(){ int maxCV; CreateLock(0); Write("Making CV's...\n", sizeof("Making CV's...\n"),ConsoleOutput); for (maxCV = 0; maxCV < 255; maxCV++){ CreateCondition(maxCV); } Fork(test1); Fork(test2); Yield(); Write("Destroying CV's...\n", sizeof("Destroying CV's...\n"), ConsoleOutput); for (maxCV = 0; maxCV < 255; maxCV++){ DestroyCondition(maxCV); } Write("CV's destroyed.\n", sizeof("CV's destroyed.\n"), ConsoleOutput); }
/* tests Createcv function by showing that * lock IDs are added in order, */ void CVTest1() { /* tests error checks in create cv */ PrintF("\nTest 1 - Trying to create CV with invalid size:\n", sizeof("\nTest 1 - Trying to create CV with invalid size:\n"), 0, 0); myCV = CreateCondition("cv", -1); PrintF("Trying to create CV with invalid address:\n", sizeof("Trying to create CV with invalid address:\n"), 0, 0); myCV = CreateCondition((char* )(5000), 2); /*tests that create works correctly, even after one is deleted */ myCV = CreateCondition("mycv", 4); myCV1 = CreateCondition("mycv1", 5); myCV2 = CreateCondition("mycv2", 5); DestroyCondition(myCV2); myCV3 = CreateCondition("mycv3", 5); PrintF("The CV IDs printed should be: 0 1 2 3\n", sizeof("The CV IDs printed should be: 0 1 2 3\n"), 0, 0); PrintF("The CV IDs are: ", sizeof("The CV IDs are: "), 0, 0); PrintF("%d %d %d %d\n", 12, myCV + myCV1*1000, myCV2 + myCV3*1000); }
int main() { int lock, condition, monitor, value, i; lock = CreateDistLock("DistLock", 8); condition = CreateDistCondition("DistCV",6); monitor = CreateDistMonitor("MonitorTest", 11, 10); AcquireDistLock(lock); /* Requires another program to be run that signals the lock*/ WaitDistCondition(condition, lock); for(i = 0; i < 10; i++) { SetDistMonitor(monitor, i, i); } for(i = 0; i < 10; i++) { value = GetDistMonitor(monitor, i); PrintF("monitor[%d]: %d", sizeof("monitor[%d]: %d"), i, value); } DestroyDistMonitor(monitor); ReleaseDistLock(lock); DestroyCondition(condition); DestroyDistLock(lock); }
int DestroyAllLocksCV() { int iInitCntr=0; /*Delete all used locks and CVs*/ DestroyLock(CustDataLock); DestroyLock(InventoryLock); DestroyLock(MgrCookStatUpdateLock); DestroyLock(InventoryLock); DestroyLock(SigCustListLock); DestroyLock(GrabedFoodLock); DestroyLock(EatInCustWaitingForFoodLock); DestroyLock(ToGoCustWaitingForFoodLock); DestroyLock(ToGoGrabedFoodLock); DestroyLock(MgrCookStyleLstLock); DestroyLock(MonitorAmtOfMoneyLock); DestroyLock(OTStatusUpdateLock); DestroyLock(CookedFoodLock); DestroyLock(TableAllotedCustLock); DestroyLock(WaitersQLock); DestroyLock(TotalTablesUpdateLock); DestroyLock(TblNeededCustLock); DestroyLock(FoodToBeCookedUpdateLock); DestroyLock(CustCountLock); DestroyLock(OTCountLock); DestroyLock(WaiterCountLock); DestroyLock(custLineLock); DestroyLock(AliveCustCountLock); DestroyLock(SleepingWaiterCountLock); DestroyLock(ActiveOTCountLock); iInitCntr=0; for(iInitCntr=0;iInitCntr<MAX_SIZE;iInitCntr++) { DestroyLock(NeedInventoryLock[iInitCntr]); DestroyLock(OrderTakerLock[iInitCntr]); DestroyLock(NeedTableLock[iInitCntr]); DestroyLock(NeedWaitersLock[iInitCntr]); } /*Print1("MAX LOCK COUNT =%d\n",NeedWaitersLock[iInitCntr]);*/ iInitCntr=0; /*************************************************************************************** Intialization of all Condition Variables ***************************************************************************************/ DestroyCondition(CookQCV); DestroyCondition(custWaitingCV); DestroyCondition(WaitersCV); iInitCntr=0; for(iInitCntr=0;iInitCntr<MAX_SIZE;iInitCntr++) { DestroyCondition(OTWaitingCV[iInitCntr]); DestroyCondition(NeedInventoryCV[iInitCntr]); DestroyCondition(NeedTableCV[iInitCntr]); DestroyCondition(NeedWaitersCV[iInitCntr]); } iInitCntr=0; return 1; }