readme

来自「ace开发环境 用来开发网络程序 其运用了设计模式、多平台、C++等多种知识」· 代码 · 共 99 行

TXT
99
字号
deadlock_detection_testThis example contains two deadlock tests, mutex and rwlock tests.% ./deadlock_detection_test -u./deadlock_detection_test:[-r test readers/writer locks][-n <iterations>][-h <remote host>][-p <remote port>][-i ignore deadlock]For both mutex and rwlock tests, -h and -p specify to use remotemutexes.  -i specifies to ignore deadlock.  -n is repetitions throughthe respective algorithms (default 100).  Both tests also use TokenInvariants to ensure correctness of the mutexes and readers/writerlocks.------------------------------------------------------------If you run ./deadlock_detection_test without -r, then the followingmutex test is run.The mutex test spawns two threads which attempt to deadlock.Logically, there are two tokens A and B.  Here is what both threadstry to do:Thread 1		Thread 2--------		--------Repeat 100 times	Repeat 100 times  acquire A		  acquire B  acquire B		  acquire A  release A and B	  release A and Brepeat			repeatNotice that A and B are reversed in 1 and 2.  If the token manager(which is not in the public interface, but hidden behindACE_Local_Mutex) works properly, they should detect the deadlock.  Ifa thread detects deadlock, the resources held are released, and itstarts the whole process over again.What can be confusing about the test program is all the other tricksI'm pulling to test other aspects of the library.  For instance, I'musing both "global" and "local" ACE_Local_Mutexes.  This is to testthe ability to have multiple threads using one token proxy as well asmultiple threads each using their own proxies.  All the while, thesame logical token is being used.  If this doesn't make sense, don'tworry about it.  Just use the ACE_Local_Mutex any way you want.Another confusing trick is that I'm testing recursive acquisition.(Two acquires in a row.)  I have to make sure that the token managerdoesn't detect a recursive acquire as deadlock.To run a test, simply type:% ./deadlock_detection_testThis should run 100 times through the above pseudo code.  If theapplication halts, then we have trouble.  It should never ever halt.I've included a little flag with the ACE_Local_Mutex class to allowdeadlock detection to be ignored.  So, if you run the test as follows,deadlock detection will be ignored.% ./deadlock_detection_test -iIn this case, the application should only run about a second beforedeadlock occurs and the application halts.  This is good.------------------------------------------------------------If you run ./deadlock_detection_test *with* -r, then the followingrwlock test is run:There are four tokens and four threads in the rwlock test.  Thereaders/writer tokens are:reader firstwriter first 1writer first 2writer first 3There are three reader threads that only acquire reader locks on theabove tokens.  Each of the reader threads first acquire "reader first"and then one "writer first <tid>" (where <tid> is the correspondingthread's id).  So reader thread 1 acquires "reader first" and then"writer first 1".There is a single writer thread that uses the following algorithm:repeat 100  acquire "writer first 1"  acquire "reader first"  acquire "writer first 2"  acquire "reader first"  acquire "writer first 3"  acquire "reader first"This strange mix of readers and writer create an interesting graph oftokens that the deadlock detection algorithm must traverse.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?