If you have a resource (say, a global list of books, for example), and you have two threads that can modify this list. There are many situations where the list data will be inconsistent.
- (Topic A reads the book and displays its data)
- (Thread B deletes the same book while data is being used by thread A)
- (Thread A now wants to add some information to the Book)
So, you must make your code thread safe so that at any time only one thread can have write access to the list of books.
Deadlocking , mentioned by SpyrosP, occurs when Thread A locks a List for writing and waits for Thread B to add data to the list. Because both threads will wait for each other to do something that they cannot do. This only happens if the thread protection mechanism is not working properly.
Chris
source share