diff options
author | Benoit Foucher <benoit@zeroc.com> | 2013-02-13 10:00:13 -0500 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2013-02-13 10:00:13 -0500 |
commit | d9f4152395e543ca5626d0811e1b21f30f9ff754 (patch) | |
tree | 80e5dab15f825c28fbd848d1b4c551cddab88850 /cpp/test/IceUtil/priority/PriorityInversion.cpp | |
parent | Added missing header to MutexProtocol.cpp (diff) | |
download | ice-d9f4152395e543ca5626d0811e1b21f30f9ff754.tar.bz2 ice-d9f4152395e543ca5626d0811e1b21f30f9ff754.tar.xz ice-d9f4152395e543ca5626d0811e1b21f30f9ff754.zip |
Fixed ICE-5230 - priority inversion test failure
Diffstat (limited to 'cpp/test/IceUtil/priority/PriorityInversion.cpp')
-rw-r--r-- | cpp/test/IceUtil/priority/PriorityInversion.cpp | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/cpp/test/IceUtil/priority/PriorityInversion.cpp b/cpp/test/IceUtil/priority/PriorityInversion.cpp index a4d7e8ac30d..36aec536e69 100644 --- a/cpp/test/IceUtil/priority/PriorityInversion.cpp +++ b/cpp/test/IceUtil/priority/PriorityInversion.cpp @@ -30,16 +30,16 @@ long fib_num ( long n) { if ( n == 0) { - return 0; + return 0; } - + else if ( n == 1 ) { - return 1; + return 1; } else { - return fib_num( n -1) + fib_num(n-2); + return fib_num( n -1) + fib_num(n-2); } } @@ -57,14 +57,31 @@ public: _high(high), _medium(medium), _low(low), + _acquired(0), _monitor(monitor) { } + void waitAcquired() + { + Monitor<Mutex>::Lock lock(_monitor); + while(_acquired == 0) + { + _monitor.wait(); + } + } + + void acquired() + { + Monitor<Mutex>::Lock lock(_monitor); + ++_acquired; + _monitor.notifyAll(); + } + void waitAll() { Monitor<Mutex>::Lock lock(_monitor); - while(_mediumBegin < _cores) + while(_mediumBegin < _cores || _highBegin == 0) { //Wait until all task are ready to compete by processors _monitor.wait(); @@ -128,6 +145,7 @@ private: int _high; int _medium; int _low; + int _acquired; Monitor<Mutex>& _monitor; IceUtil::Mutex _mutex; }; @@ -166,6 +184,7 @@ public: { taskCollector()->taskBegin(priority); Mutex::Lock lock(_mutex); + taskCollector()->acquired(); taskCollector()->waitAll(); fib_num(30); taskCollector()->taskEnd(priority); @@ -190,8 +209,9 @@ public: { taskCollector()->taskBegin(priority); RecMutex::Lock lock(_mutex); + taskCollector()->acquired(); taskCollector()->waitAll(); - fib_num(30); + fib_num(40); taskCollector()->taskEnd(priority); } @@ -235,6 +255,11 @@ public: _shared->run(getPriority()); } + void waitAcquired() + { + _shared->taskCollector()->waitAcquired(); + } + private: SharedResourcePtr _shared; @@ -292,7 +317,7 @@ void PriorityInversionTest::run() { int cores, high, medium, low, timeout; - timeout = 2; + timeout = 30; #ifdef _WIN32 return; //Priority inversion is not supported by WIN32 #else @@ -313,21 +338,22 @@ PriorityInversionTest::run() { Monitor<Mutex> monitor; TaskCollectorPtr collector = new TaskCollector(cores, high, medium, low, monitor); - vector<ThreadControl> threads; - + vector<ThreadControl> threads; + SharedResourcePtr shared = new SharedResourceMutex(collector); // // Create one low priority thread. // - ThreadPtr lowThread = new Task(shared); + TaskPtr lowThread = new Task(shared); threads.push_back(lowThread->start(128, low)); + lowThread->waitAcquired(); // // Create one high priority thread that use the same shared resource // as the previous low priority thread // - ThreadPtr highThread = new Task(shared); + TaskPtr highThread = new Task(shared); threads.push_back(highThread->start(128, high)); // @@ -369,8 +395,9 @@ PriorityInversionTest::run() // // Create one low priority thread. // - ThreadPtr lowThread = new Task(shared); + TaskPtr lowThread = new Task(shared); threads.push_back(lowThread->start(128, low)); + lowThread->waitAcquired(); // // Create one high priority thread that use the same shared resource |