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:
parent
273eb9885c
commit
3c10f05589
|
@ -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>
|
/// <summary>
|
||||||
/// Verifies that the waiting work items count and active thread count are
|
/// Verifies that the waiting work items count and active thread count are
|
||||||
/// updated by the thread pool.
|
/// updated by the thread pool.
|
||||||
|
|
|
@ -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>
|
/// <summary>A thread worker function that processes items from the work queue</summary>
|
||||||
private static void ProcessQueuedItems() {
|
private static void ProcessQueuedItems() {
|
||||||
|
|
||||||
|
@ -198,7 +206,7 @@ namespace Nuclex.Support {
|
||||||
thread.IdealProcessor = hardwareThreadIndex;
|
thread.IdealProcessor = hardwareThreadIndex;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Keep processing tasks indefinitely
|
// Keep processing tasks indefinitely
|
||||||
for(; ; ) {
|
for(; ; ) {
|
||||||
UserWorkItem workItem = getNextWorkItem();
|
UserWorkItem workItem = getNextWorkItem();
|
||||||
|
@ -231,7 +239,7 @@ namespace Nuclex.Support {
|
||||||
return threads[index];
|
return threads[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -264,7 +272,7 @@ namespace Nuclex.Support {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Delegate used to handle assertion checks in the code</summary>
|
/// <summary>Delegate used to handle assertion checks in the code</summary>
|
||||||
public static volatile ExceptionDelegate ExceptionHandler;
|
public static volatile ExceptionDelegate ExceptionHandler = DefaultExceptionHandler;
|
||||||
|
|
||||||
#if !XBOX360
|
#if !XBOX360
|
||||||
/// <summary>Retrieves the calling thread's thread id</summary>
|
/// <summary>Retrieves the calling thread's thread id</summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user