Formal testing for multithreaded code

Started by
14 comments, last by chairthrower 15 years, 9 months ago
Is it appropriate to use unit testing to verify the thread-safety of code, or is there a special name for this type of testing? I'd reckon that in a non-trivial multi-threaded app, you're certain to have loopholes where problems are possible, even if they are very unlikely to actually occur.
Advertisement
No, there isn't. The problem is that unit testing has a lot of trouble catching race conditions and other surprising multi-threaded behavior, because the hardware and the other programs running on the computer have a non-deterministic impact on testing.

Ultimately, you should never develop a non-trivial multi-threaded app, instead keeping yourself to a non-trivial app with trivial multi-threading. There are a lot of known techniques available to ensure that multi-threading is kept local and does not affec other parts of the program. Resist the temptation to let multi-threading overflow its bounds and permeate everything.
In theory, a unit test that achieves 100% code coverage, will test for all deterministic behavior. With multi-threaded code, this isn't even nearly sufficient criteria.
A google search for "testing concurrent-programs" returns some interesting results, including several articles.
Quote:Original post by ToohrVyk
Ultimately, you should never develop a non-trivial multi-threaded app, instead keeping yourself to a non-trivial app with trivial multi-threading. There are a lot of known techniques available to ensure that multi-threading is kept local and does not affec other parts of the program. Resist the temptation to let multi-threading overflow its bounds and permeate everything.
I don't think you can develop a complex app which effectively uses threading by trying to keep threading in its own little box... this isn't a game with a render loop, AI loop, logic loop etc, but an event driven system where the events are basically fired by several external threads.
Quote:Original post by d000hg
I don't think you can develop a complex app which effectively uses threading by trying to keep threading in its own little box... this isn't a game with a render loop, AI loop, logic loop etc, but an event driven system where the events are basically fired by several external threads.


You won't be able to develop a complex app which effectively uses threading by letting threads play around everywhere. The human brain is simply too limited to handle it. You need some kind of separation somewhere, otherwise you'll just end up missing a race condition somewhere.

Even if your system does not fit the "render loop, AI loop, logic loop" common in video games, there are many other parallel architectures that you can apply (sinks/pipelines, communicating servers, service-based designs etc) to reduce the pervasiveness of threading.
Quote:Original post by d000hg
Is it appropriate to use unit testing to verify the thread-safety of code


Typically no unit testing is for units of functionality say a function or a class. Once you move on from the unit level it is no longer called unit testing, but integration testing since you are integrating units together.
Victor - can you point to resources on good thread architecture by established authors who know their stuff? Free and paid.
Quote:Original post by thedustbustr
Victor - can you point to resources on good thread architecture by established authors who know their stuff? Free and paid.


In a general sort of way, have you looked at parallel design strategies out there? ACE's Active objects,ACE's services, OpenMp's compiler directives, MPI's share nothing and pass messages, Intel's TBB(similar to openmp but template based instead of compiler directives). Those are all implementations of different design patterns for parallel development reading up on them should help expose you to their underlying theories of parallel development.
Quote:Original post by thedustbustr
Victor - can you point to resources on good thread architecture by established authors who know their stuff? Free and paid.


Pi-calculus (book, wikipedia) is a sound theoretical starting point for examining message-based architectures. Wikipedia also has a short list of patterns that can be at home in a concurrent environment. Although for Java, this book hints at some architecture possibilities despite Java's suicide-inducing approach to concurrent programming.

This topic is closed to new replies.

Advertisement