Jump to content
  • Advertisement
Sign in to follow this  
d000hg

Formal testing for multithreaded code

This topic is 3725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
A google search for "testing concurrent-programs" returns some interesting results, including several articles.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!