If there is some code that 2 threads trying to write to the same object at the same time, my understanding is that it will not generate any compile-time error, which is the part of the reason why debugging multithreading program is so difficult. But will this generate a run-time error / exception?
Can anyone suggest any good multithreading debug techniques?
Thanks.
Accessing the same object from inside two or more different threads would not generate an error either in run time or in a debugger BUT it most probably would screw around with the object in ways that you did not intend to.
The way to handle it in a multi-threaded environment safely is to use mutexes and semaphores.
For mutexes check the wikipedia link.
Mutexes are generally used when you want to limit the access to an object by only one thread at a time.
Semaphores on the other hand are a more generic case (mutexes are actually a special case of a semaphore) which have a counter that each thread will increase/decrease depending on the activation/deactivation of the semaphore. When the semaphore reaches 0 it will lock itself and the thread that caused it. For more information on semaphores check the wikipedia page
If you want more specific advice, then I suggest you give us information on the Operating system you are targeting and/or the API you are using since anything having to do with threads (mutexes,semaphores e.t.c.) are OS-specific