multithreading - How to detect and debug multi-threading problems? -


This is a follow-up, where I did not find any input at this point. Here's a brief question:

Is it possible to detect and debug problems with multi-threaded code?

Often we have to tell our customers: "We can not reproduce the problem here, so we can not fix it. Please tell us, we will fix it. " If I know that this is a multi-threading problem, then this is some kind of dirty answer, but mostly I do not. How do I know that the problem is a multi-threading problem and how to debug it?

I want to know whether there are any special logging frameworks, or debugging techniques, or code inspectors, or anything to help solve such issues. The general approach is welcome if any answer should be related language then keep it in NET and Java.

Threading / concurrency problems are extremely difficult to replicate - which One of the reasons is that you should be designed to avoid or at least minimize the possibilities. This is because invariant objects are very valuable, try to separate the temporary objects into one thread, and then carefully control the exchange of volatile objects between the threads. Trying the program with the object's design instead of "shared" objects, use the fully synchronized control objects (which are easy to reason with about it), and use a second object from a synchronized object Avoid, which should also be synchronized - that is, try to keep them in vain. Your best defense is a good device. The Ain.

Deadlocks is easy to debug, if you can get stack trace when deadlock. Looking at the trace, most of which detect the deadlock, the reason is easy to understand and then tells the reason about the code and how to fix it. With Deadlock, this will always be a problem in getting the same locks in separate orders.

Live lock is hard - in case of error, the system is able to follow

race conditions to repeat Are very hard to detect, and manual code reviews are also difficult to identify with. With them, in addition to extensive testing to repetit the route I usually take, I have to reason on the possibilities, and try to log on information to prove or prove the principles. If you have direct evidence of state corruption, then you can think of potential causes on the basis of corruption.

A more complex system is to find compatibility errors in the link, and argue about it. Use tools like JVisualVM and Remote Connect Professor - If you can connect to a system in an error condition and observe threads and objects, they can be a life saving.

Also, beware of differences in possible practice, which depend on the number of CPU cores, pipelines, bus bandwidth etc. Changes in hardware can affect your ability to replicate the problem. Some problems will only show the other people of the single-core CPU only on the multi-core

One last thing, try using concurrent objects distributed with system libraries - like Java java.util.concurrent is your friend, it is difficult to write your concurrency control objects and Is full of danger; Leave the experts, if you have any options.


Comments