Found the synchronization problem in the affine thread pool - the auto reset event was being set twice before even a single thread pool thread made it through the WaitOne() - fixed by using a semaphore; implemented a semaphore that should work in the XBox 360; wrote unit tests for said semaphore; added messages to the affine thread pool's unit tests to make debugging easier
git-svn-id: file:///srv/devel/repo-conversion/nusu@177 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
09247541f2
commit
874fe0a9e4
6 changed files with 381 additions and 10 deletions
|
@ -281,20 +281,35 @@ namespace Nuclex.Support {
|
|||
// works on a first come first serve basis, but we don't want to rely on this
|
||||
// implementation detail in the unit test.
|
||||
for(int index = 0; index < eventCount; ++index) {
|
||||
Assert.IsTrue(tasks[index].StartEvent.WaitOne(1000));
|
||||
Assert.IsTrue(
|
||||
tasks[index].StartEvent.WaitOne(10000),
|
||||
"Task " + index.ToString() + " was started"
|
||||
);
|
||||
}
|
||||
|
||||
// All Thread should now be active and no work items should be waiting
|
||||
Assert.AreEqual(createdTasks, AffineThreadPool.ActiveThreads);
|
||||
Assert.AreEqual(0, AffineThreadPool.WaitingWorkItems);
|
||||
Assert.AreEqual(
|
||||
createdTasks, AffineThreadPool.ActiveThreads,
|
||||
"ActiveThreads property equals number of tasks"
|
||||
);
|
||||
Assert.AreEqual(
|
||||
0, AffineThreadPool.WaitingWorkItems,
|
||||
"No waiting work items are in the queue"
|
||||
);
|
||||
|
||||
// Add a task to the queue and make sure the waiting work item count goes up
|
||||
AffineThreadPool.QueueUserWorkItem(delegate(object state) { });
|
||||
Assert.AreEqual(1, AffineThreadPool.WaitingWorkItems);
|
||||
Assert.AreEqual(
|
||||
1, AffineThreadPool.WaitingWorkItems,
|
||||
"Added work item is waiting in the queue"
|
||||
);
|
||||
|
||||
// The same again. Now we should have 2 work items sitting in the queue
|
||||
AffineThreadPool.QueueUserWorkItem(delegate(object state) { });
|
||||
Assert.AreEqual(2, AffineThreadPool.WaitingWorkItems);
|
||||
Assert.AreEqual(
|
||||
2, AffineThreadPool.WaitingWorkItems,
|
||||
"Both added work items are waiting in the queue"
|
||||
);
|
||||
|
||||
// Let the WaitTasks finish so we're not blocking the thread pool any longer
|
||||
for(int index = 0; index < eventCount; ++index) {
|
||||
|
@ -303,7 +318,10 @@ namespace Nuclex.Support {
|
|||
|
||||
// Wait for the tasks to end before we get rid of them
|
||||
for(int index = 0; index < eventCount; ++index) {
|
||||
Assert.IsTrue(tasks[index].FinishEvent.WaitOne(1000));
|
||||
Assert.IsTrue(
|
||||
tasks[index].FinishEvent.WaitOne(1000),
|
||||
"Task " + index.ToString() + " has finished"
|
||||
);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
@ -311,7 +329,6 @@ namespace Nuclex.Support {
|
|||
tasks[createdTasks].Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue