void main() { int lck1=1, lck2=2, lck3=3; Print("\n Checking Wrong Working of Releaseing of Locks. \n\0",1,1,1); lck1 = CreateLock("lock1", 5); Print("\n lck1 Has Been Created in testCase_4. \n\0",1,1,1); lck2 = CreateLock("lock2", 5); Print("\n lck2 Has Been Created in testCase_4. \n\0",1,1,1); Acquire(lck1); Print("\n lck1 Has Been Acquired in testCase_4. \n\0",1,1,1); Acquire(lck2); Print("\n lck2 Has Been Acquired in testCase_4. \n\0",1,1,1); Release(lck1); Print("\n lck1 Has Been Released in testCase_4. \n\0",1,1,1); Release(lck2); Print("\n lck2 Has Been Released in testCase_4. \n\0",1,1,1); Print("\n Error Should Print That lck3 Does Not Exist. \n\0",1,1,1); Release(lck3); DeleteLock(lck1); Print("\n lck1 Has Been Deleted in testCase_4. \n\0",1,1,1); DeleteLock(lck2); Print("\n lck2 Has Been Deleted in testCase_4. \n\0",1,1,1); Exit(0); }
int main() { Write("Test 5 creates lock and cv\n", sizeof("Test 5 creates lock and cv\n"), ConsoleOutput); lock = CreateLock("lock", sizeof("lock")); cv = CreateCV("cv", sizeof("cv")); for (i = 0; i < 50000; i++) { Yield(); } Write("Test 5 destroys lock and cv\n", sizeof("Test 5 destroys lock and cv\n"), ConsoleOutput); DestroyLock(lock); DestroyCV(cv); }
void t1_t1(){ /*checks destroy and create invalid input is handled properly*/ indexcheck1= CreateLock("abc", -1); indexcheck2=DestroyLock(indexcheck1+100); indexcheck3=DestroyLock(-100); if (indexcheck1==-1 && indexcheck2==-1 && indexcheck3==-1){ Write("passed: create/destroyLOCK validates input\n", sizeof("passed: create/destroyLOCK validates input\n"), 1); } else{ Write("failed: create/destroyLOCK validates input\n", sizeof("failed: create/destroyLOCK validates input\n"), 1); } }
void main() { count =0; a = CreateLock("lock1",5); b = CreateCV("cond1",5); Fork(thread1); Fork(thread2); Yield(); Yield(); Yield(); }
void main() { a = CreateLock("lock1",5); b = CreateCV("cond1",5); count =0; for( j=0;j<105;j++) { Fork(thread1); } }
CTrMirrorBuffer::CTrMirrorBuffer(uint32 uDataSize, uint32 uDataNum) { CreateLock(&m_Lock); m_pRBPatchMgr = new CMirrorRBPatchMgr; m_pWBPatchMgr = new CMirrorWBPatchMgr; m_pDiscardedCmdMgr = new CTrDiscardedCmdMgr; CreateTripleBuffer(uDataSize, uDataNum); m_pWriteBuffer->SetVersion(1); //首先就把write的版本设置为1 }
void main() { lock = CreateLock("lock"); AcquireLock("lock"); Print("Client 1 has the lock..",-1,-1,-1); ReleaseLock("lock"); Exit(0); }
void client2() { int Lock1,CV1; Lock1=CreateLock("USERLOCK",8); CV1=CreateCondition("USERCV",6); Acquire(Lock1); Signal(CV1,Lock1); Release(Lock1); }
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); }
/*client 1 functions show the proper functioning of signal and wait calls*/ void client1() { int Lock1,CV1,CV2; Lock1=CreateLock("USERLOCK",8); CV1=CreateCondition("USERCV",6); Acquire(Lock1); Wait(CV1,Lock1); Release(Lock1); }
int main() { int lock; int cv; cv= CreateCV("lock",4); lock= CreateLock("cv",2); AcquireLock(lock); WaitCV(lock,cv); ReleaseLock(lock); Exit(0); }
int main() { Write("\n\n Test Suite 2\n\n (bracketed terms denote the testsuites)\n\n",100,1); Write("\n[2] Execing testsuite2_1\n",100,1); i = Exec("../test/testsuite2_1",20); Write("\n[2] Execing testsuite2_2\n",100,1); i = Exec("../test/testsuite2_2",20); visitorCountLock = CreateLock("vclock",6); for(i=0;i<MAX;i++) { Fork(TestFunc); } Exit(0); }
int test() { int int2=0; for (int2=0;int2<550;int2++) { i=CreateLock("locksTesting"); AcquireLock(i); ReleaseLock(i); Print("New loop is %d\n",int2,-1,-1); if (int2 % 10 == 0) DestroyLock(i); } Exit(0); }
main() { int w = CreateLock("lock_test"); Acquire(w); Release(w); if(w>=0){ Write(" Testing lock creation...Pass\n" , 50, ConsoleOutput ); } else { Write(" Testing lock creation...Fail\n" , 50, ConsoleOutput ); } }
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); }
void initScreeningOfficers() { int i; NumActiveScreeningOfficers = 0; #define officer ScreeningOfficers[i] for (i = 0; i < NUM_SCREENING_OFFICERS; ++i) { officer._lock = CreateLock(concatNumToString("officer_lock_", sizeof("officer_lock_"), i), 14); officer._commCV = CreateCV(concatNumToString("officer_commCV_", sizeof("officer_commCV_"), i), 20); officer._state = BUSY; officer._passCount = 0; officer._currentPassenger = -1; officer._myNum = i; officer._done = false; } #undef officer }
int main() { lock1 = CreateLock("Lock1", 5, 0); lock2 = CreateLock("Lock2", 5, 0); deadLock1 = CreateLock("deadLock1", 9, 0); deadLock2 = CreateLock("deadLock2", 9, 0); lockToBeDestroyed = CreateLock("lockToBeDestroyed", 17, 0); theLockThatDoesntExist = lock1+10; Write("Testing invalid actions for locks\n", 34, ConsoleOutput); Write("Acquiring theLockThatDoesntExist, should give error\n", 52, ConsoleOutput); Acquire(theLockThatDoesntExist); Write("Releasing theLockThatDoesntExist, should give error\n", 52, ConsoleOutput); Release(theLockThatDoesntExist); Write("Destroying theLockThatDoesntExist, should give error\n", 53, ConsoleOutput); DestroyLock(theLockThatDoesntExist); Write("Destroying lockToBeDestroyed, should be successful\n", 51, ConsoleOutput); DestroyLock(lockToBeDestroyed); /*Write("Reacquiring lockToBeDestroyed, should give error\n", 49, ConsoleOutput); Acquire(lockToBeDestroyed);*/ Fork(t1,0); Fork(t2,0); /*Write("Testing Locks\n", 14, ConsoleOutput) lockNum = CreateLock("nameLock"); Acquire(lockNum); condNum = CreateCondition("someCondition"); Signal(lockNum, condNum); Broadcast(lockNum, condNum); Release(lockNum); DestroyLock(lockNum); Write("Locks complete\n", 15, ConsoleOutput); Exec("../test/halt"); Exec("../test/halt"); */ Write("Finshing lockfiles.c\n", 22, ConsoleOutput); Exit(0); }
int main() { int cv1=0; int l1=CreateLock(); Write("\n Running cvtest5.c\n",22,1); Write("\nTESTING: CVTEST5.C TRIES TO ACCESS THE CV NOT CREATED BY IT",60,1); Exec("../test/cvtest1",15); Yield(); Yield(); Yield(); WaitCondition(cv1,l1); SignalCondition(cv1,l1); BroadcastCondition(cv1,l1); Exit(0); }
int main() { int lock1; unsigned int i=0; Write("\n Running locktest1.c\n",22,1); for(i=0;i<67000;i++) { lock1=CreateLock(); if(lock1==-1) { break; } } Exit(0); }
/* * 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=(cc_number * 2) ; i <= (cc_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); custCondVar[i][j]=mtCb.custGrp[i].cust[j].name; CreateCV(mtCb.custGrp[i].cust[j].name); } } {/* locks and CVs for concession clerks */ ccLock[cc_number]=mtCb.cc[cc_number].name; CreateLock(mtCb.cc[cc_number].name); ccCondVar[cc_number]=mtCb.cc[cc_number].name; CreateCV(mtCb.cc[cc_number].name); } }
void main() { a = CreateLock("lock1",5); b = CreateCV("cond1",5); Fork(thread1); Fork(thread2); Fork(thread3); Fork(thread4); }
void main() { count =0; a = CreateLock("lock1",5); b=a+2; Fork(thread1); Yield(); }
CMemThreadMgr::CMemThreadMgr() { m_bEndThreads=false; m_bHandleJobDone=true; m_pThread=NULL; CreateSemaphore(&m_smJobQueue,0,INT_MAX); CreateSemaphore(&m_smFetchSymbol, 0, INT_MAX); CreateLock(&m_slkJobQueue); m_pThread = new CMemThread(this); Ast(! gs_pInst); gs_pInst=this; }
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); }
int main(){ lk1 = CreateLock("lk1", sizeof("lk1")); cv1 = CreateCondition("cv1", sizeof("cv1")); Acquire(lk1); Write("Test 2:Acquired lk1 \n", sizeof("Test 2:Acquired lk1 \n"), ConsoleOutput); Signal(lk1, cv1); Write("Test 2:Signalled lk1 \n", sizeof("Test 2:Signalled lk1 \n"), ConsoleOutput); Wait(lk1, cv1); Write("Test 2:I was signalled lk1 \n", sizeof("Test 2:I was signalled lk1 \n"), ConsoleOutput); Release(lk1); Write("Test 2:Released lk1 \n", sizeof("Test 2:Released lk1 \n"), ConsoleOutput); }
int main() { int lock1 = CreateLock("Lock1", 5); int i; for(i = 0; i < 10; i++){ Acquire(lock1); Fork((void*)print1, "Print", 5, 1); Release(lock1); Acquire(lock1); Fork((void*)print2, "Increment", 9, 2); Release(lock1); } DestroyLock(lock1); Exit(0); }
/* * Calendar functions entry */ EXPORT ER dt_main(INT ac, UB* av[]) { ER er; T_DSSY dssy; if (ac < 0) { /* Stop other tasks from executing SVC */ Lock(&dtLock); /* Unregister subsystem */ tk_def_ssy(DT_SVC, NULL); /* Delete lock */ DeleteLock(&dtLock); return E_OK; } /* Create lock */ er = CreateLock(&dtLock, "dtLk"); if (er < E_OK) { goto err_ret0; } /* Register subsystem */ dssy.ssyatr = TA_NULL; dssy.ssypri = DT_PRI; dssy.svchdr = (FP)svcEntry; dssy.breakfn = NULL; dssy.startupfn = NULL; dssy.cleanupfn = NULL; dssy.eventfn = NULL; dssy.resblksz = 0; er = tk_def_ssy(DT_SVC, &dssy); if (er < E_OK) { goto err_ret1; } return E_OK; err_ret1: DeleteLock(&dtLock); err_ret0: return er; }
void main() { Print("\n tcase6: Checking Working of Wait and Signal. \n",1,1,1); CreateLock("lock1"); /* Print("\n tcase6: lock1 Has Been Created. \n",1,1,1); */ CreateCV("cv1"); /* Print("\n tcase6: cv1 Has Been Created. \n",1,1,1); */ Print("\n tcase6: Going on wait on 'cv1' using 'lock1' that is not acquired. Will not go on wait.\n",1,1,1); Wait("cv1","lock1"); Print("\nERROR - tcase6: Could not go on wait on 'cv1' using 'lock1'.\n",1,1,1); Print("\n tcase6: Signalling on 'cv1' using 'lock1' that is not acquired. Will not Signal.\n",1,1,1); Signal("cv1","lock1"); Print("\nERROR - tcase6: Could not Signal on 'cv1' using 'lock1'.\n",1,1,1); Acquire("lock1"); /* Print("\n tcase6: lock 1 Has Been Acquired. \n",1,1,1); */ Print("\n tcase6: Going on wait on 'cv2' that is not created using 'lock1'. Will not go on wait.\n",1,1,1); Wait("cv2","lock1"); Print("\n ERROR - tcase6: Could not go on wait on 'cv1' using 'lock2'.\n",1,1,1); Print("\n tcase6: Signalling on 'cv2' that is not created using 'lock1'. Will not Signal.\n",1,1,1); Signal("cv2","lock1"); Print("\nERROR - tcase6: Could not Signal on 'cv1' using 'lock1'.\n",1,1,1); Release("lock1"); /* Print("\n tcase6: lock 1 Has Been Released. \n",1,1,1); */ /* DeleteCV("cv1"); Print("\n tcase6: cv1 Has Been Deleted. \n",1,1,1); DeleteLock("lock1"); Print("\n tcase6: Lock 1 Deleted. \n",1,1,1); DeleteLock("lock2"); Print("\n tcase6: Lock 2 Deleted. \n",1,1,1); */ Exit(0); }
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); }
int main() { lock1 = CreateLock("0", sizeof("0")); lock2 = CreateLock("0", sizeof("0")); lock3 = CreateLock("0", sizeof("0")); lock4 = CreateLock("0", sizeof("0")); lock5 = CreateLock("0", sizeof("0")); lock6 = CreateLock("0", sizeof("0")); Fork(t5_t2); Fork(t5_t3); Yield(); }