re-entranty and thread-safe
I have to test a library to make sure its re-entrant and thread-safe. What would be the best approach to this. My first idea is writing test code to call the library from multiple threads, then testing the results of each thread. Are there any tools which would help, or ways to monitor that the treads are not interfering with each other.
Re: re-entranty and thread-safe
Threads, and parallel processing, constitute an advanced topic that only a well experienced person, in this area, would be qualified to test.
It is my experience that only a small fraction of developers properly understand threading and synchronization. And since it is a very technical topic, I assume that the percentage is even lower.
The first type of testing that most people do is the "thrashing" testing that you propose. That is, simply run the code in a variety of threads and see if it works.
Due to the manner in which scheduling is done on operating systems, this type of testing, even if performed with hundreds of threads millions of times, is good at catching only the most mundane of synchronization errors.
Well planned testing, based on synchronization requirements, can yield stronger results for some of the more common mistakes. Here I mean that you should make your threads work together to test the code, in essense, created a synchronized multi-threaded testing harness. This is difficult, and requires only slightly less skill than writing the code you plan on testing.
Yes, this type of testing still does not catch exotic errors, or fractional timing errors. Errors in sychronization are best found by tracing all paths of possible execution through the code -- manually tracking via state machine (big piece of paper usually).
The code review is the most promising, as you can clearly identify all weak points (an experienced developer will know what these weak points are). Once weak points are identified you can write some planned tests for these, and do theoretical walk-throughs (as automation may not be able to create the theoretical possibly situations).