Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
please share if any techniques are available for debugging a multi-threaded application in C++? my basic need include - which tool to use, what is the state of other threads when a crash occurred, how to know the state of detached threads.

What I have tried:

tried to see gdb's 'backtrace' output, but not much helpful.
Posted
Updated 1-Aug-16 6:06am

1 solution

You must debug them as any other C++ app - but some tips.

A good approach is often to run and debug all threads at first in one thread (as function call) to find the problems and then "outsource" the stabil function in a thread. A detached thread should exit execution. Make some output at the exit point.

You can write to system logs and include the thraed id or to a own log file, but a different for every thread. Name them after the thread id. Set breakpoint before you start debugging.

The biggest problem is often the syncronization between threads, so the carefully access common data or files. The article Thread Synchronization for Beginners gives a good overview about different technologies. Understand and learn these professional technologies: they make multithreading safe. Use some static global data for common thread data.

My everyday experience is NEVER EVER to allocate and deallocate byte in different threads: Memory stays in the thread. Copy it when needed!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900