when more than one thread involve in our application we need to synchronize our shared data access.
This synchronization can look like a simple thing in the first but if we look close at the details, we will see the problems that we need to be aware of them. I want to talk about two things that can happen when we synchronize data access.
Before i explain what each means, I want to mention that thread can being in either two modes: User-Mode and Kernel-Mode. User-mode means that the OS not involved in the process, in the other side, the kernel-mode means that the OS kernel code managed the process of the thread. Each of the method has his upsides and downsides. In general, the user-mode is more efficient.
This is the more known problem than the other (livelock). Deadlock including transition to kernel mode (because the use of kernel object) and then sleep. It means that first thread access to a critical section and second thread sleep and wait to wake up when the first thread exit the critical section. The problem occur if the first thread never exit from the critical section (if he wait on a second thread lock for example) and then the second thread will keep sleeping forever. Because we talk about kernel-mode this mean that the second thread does not consume CPU resources.
This is like first example in the sense that two threads will block each other but here the two threads doesn’t sleep. They try again and again to do their job but because non of them wait and let the second to do is work, both of them keeping to consume CPU resources without success to finish their job.
So the two concepts mean that our threads are threads are unable to make further progress and this is bad, the difference is if the threads waste CPU resources – livelock; or not – deadlock.