Re-added the default exception handler which will now re-throw the exception, thereby mimicking the behavior of .NET's ThreadPool; wrote unit test to verify the default exception handler is working

git-svn-id: file:///srv/devel/repo-conversion/nusu@179 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2009-09-18 21:14:27 +00:00
parent 273eb9885c
commit 3c10f05589
2 changed files with 24 additions and 3 deletions

View File

@ -249,6 +249,19 @@ namespace Nuclex.Support {
}
/// <summary>
/// Tests whether the afine thread pool's default exception handler works
/// as expected
/// </summary>
[Test]
public void TestDefaultExceptionHandler() {
Assert.Throws<ArrayTypeMismatchException>(
delegate() {
AffineThreadPool.ExceptionHandler(new ArrayTypeMismatchException("Test"));
}
);
}
/// <summary>
/// Verifies that the waiting work items count and active thread count are
/// updated by the thread pool.

View File

@ -165,6 +165,14 @@ namespace Nuclex.Support {
}
}
/// <summary>
/// Default handler used to respond to unhandled exceptions in ThreadPool threads
/// </summary>
/// <param name="exception">Exception that has occurred</param>
internal static void DefaultExceptionHandler(Exception exception) {
throw exception;
}
/// <summary>A thread worker function that processes items from the work queue</summary>
private static void ProcessQueuedItems() {
@ -198,7 +206,7 @@ namespace Nuclex.Support {
thread.IdealProcessor = hardwareThreadIndex;
}
#endif
// Keep processing tasks indefinitely
for(; ; ) {
UserWorkItem workItem = getNextWorkItem();
@ -231,7 +239,7 @@ namespace Nuclex.Support {
return threads[index];
}
}
return null;
}
#endif
@ -264,7 +272,7 @@ namespace Nuclex.Support {
}
/// <summary>Delegate used to handle assertion checks in the code</summary>
public static volatile ExceptionDelegate ExceptionHandler;
public static volatile ExceptionDelegate ExceptionHandler = DefaultExceptionHandler;
#if !XBOX360
/// <summary>Retrieves the calling thread's thread id</summary>