[svn] commit: r3577 - /branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Nov 20 16:57:11 UTC 2010
Author: vorner
Date: Sat Nov 20 16:57:10 2010
New Revision: 3577
Log:
Fix lock test
It could deadlock if the wrong thread started first
Modified:
branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc
Modified: branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc
==============================================================================
--- branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc (original)
+++ branches/trac408/src/lib/nsas/tests/zone_entry_unittest.cc Sat Nov 20 16:57:10 2010
@@ -105,6 +105,8 @@
void lockAndKeep(ZoneEntry* zone, bool* locked_self, bool* locked_other,
barrier* when)
{
+ // Wait for go signal
+ when->wait();
// Lock
ZoneEntry::Lock lock(zone->getLock());
*locked_self = true;
@@ -144,9 +146,14 @@
barrier both_second(2);
bool l1(false), l2(false);
thread t3(lockAndKeep, &z1, &l1, &l2, &both);
+ // Let this one run into the lock, not the other
+ both.wait();
thread t4(lockAndKeep, &z2, &l2, &l1, &both_second);
+ // Let it start the loop
both.wait();
- // Make sure one of them is started
+ // Let this one run to the lock and wait on it
+ both_second.wait();
+ // Make sure the threads has time now
for (int i(0); i < 100; ++ i) {
this_thread::yield();
}
@@ -156,9 +163,10 @@
// Try it the other way around (so it does not depend on the order of nameservers
thread t6(lockAndKeep, &z2, &l2, &l1, &both);
+ both.wait();
thread t5(lockAndKeep, &z1, &l1, &l2, &both_second);
both.wait();
- // Make sure one of them is started
+ both_second.wait();
for (int i(0); i < 100; ++ i) {
this_thread::yield();
}
More information about the bind10-changes
mailing list