[RESOLVED] Multi thread debugging
Hello all, Sorry Im so fresh at programming that im not really sure whats going on here.
I have 3 threads that I create in the back ground, and for some reason my program works then the next time it doesn't work. The errors are consistent but once I fix one there are completely different errors which bear no relation.
One thing I notice is when I take one step while debugging inside one of my threads the other two threads complete a full cycle. How can I have these threads step one at a time? I want to know EXACTLY what my other threads are doing when im on this step. I want to see it working how it would normally work just much slower. Debugging I do not get to see this so it is really hard to find my real errors. Thanks for any advice.
EDIT: Forgot to mention, also when debugging my program does strange things, like when im looking in a thread instead of executing the next line it restarts the thread, why would this happen? If the program is actually reacting in this way I could see why Im getting some of the errors I am getting. Otherwise Im really not sure what my issues are.
Re: Multi thread debugging
Ive more than fixed my issue with my program, going line my line and condensing for loops and adding breaks. The code does exactly the same thing as before just now its a bit cleaner. Lesson learned.
Anyone have any good tips for debugging multi threads, its the stepping that bothers me, if I take one step in the thread im looking at the other threads run a full cycle, why is that? And anyone know how I can get them to step together?
Re: Multi thread debugging
Yes, multi threading is hard to debug.
When I have situations like this, I normally write 'debug' lines to some kind of logger. It can be the console, a simple textfile or whatever you want to log too.
Re: Multi thread debugging
Code review (i.e. reading through your code in detail to rationalize why it does what it does at each step) is really important for multi-threaded debugging (and programming in general, but most especially for things that are resistant to traditional debugging methods). You'd be surprised at how many bugs you can catch just by re-reading your code in detail.
Re: Multi thread debugging
Quote:
Originally Posted by
BioPhysEngr
Code review (i.e. reading through your code in detail to rationalize why it does what it does at each step) is really important for multi-threaded debugging (and programming in general, but most especially for things that are resistant to traditional debugging methods). You'd be surprised at how many bugs you can catch just by re-reading your code in detail.
No kidding, I actually put conditions on my other threads that interact with my main thread. So the timing would be perfect and my other thread where not doing what I didn't want them to do for each step. So i had to go through line by line and well I have to say my program is not only working perfectly now but its far more efficient.
Thanks for the tips everyone!