Hey - What does this button do?
Hi. This is my first ever web log post, so please be understanding while reading it. :-)
I recently converted a block of test scheduling code from C++ to C# and decided to choose a new design paradyme. I was quite pleased with the results.
The C++ code used a list of tests that was unordered and a dynamic pool of threads that consumed the tests to execute them. There was a large amount of code to handle the thread synchronization, the dynamically growing thread pool and support for generic test execution.
The new C# code used two collections of tests and takes advantage of the built in thread pool in the .Net Framework. The basic functionality is:
- Tests get added to the "pending" collection, which sorts them as they are added, by the time they are due to execute.
- A timer is set to go off when the next test is due.
- When the timer expires the tests that are due are moved to an "executing" collection, which spins up a worker thread for each test, and a timer to track the test in case it times out.
- When a test completes, its results are stored in a "result" collection and the test is moved back to the "pending" collection.
The whole process it self perpetuating and this design really simplifies the code and makes it much more maintainable. I was also amazed at how much smaller the resulting C# code was compared to the C++ original. I'm sure the .Net Framework is largely responsible, but from a developer's standpoint, I'm still very pleased.
Howitzer
New Comments to this post are disabled