Deadlock Vs. Livelock

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.

Deadlock:

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.

Livelock:

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.

Advertisements
This entry was posted in .NET and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s