Explain the race around condition? How can it be overcome?

Submitted by: Administrator
Race conditions is a severe way crashing the server/ system at times. Generally this problem arises in priority less systems or the users who has eqal priority will be put to this problem. Race condition is a situation in which a resource D is to be serviced to a process A and the processB which holds the resoure C is to be given to the process A. So a cyclic chain occurs and no way the resources will be get shared and also the systems with equal prirority wont get the resoure so that the system wont come out of the blocked state due to race condition!

Race condition is a bug in your application, occurs when the result of your application depends on which one of two or more threads reaches a shared block of code first. In this case, the application output changes each time it is executed!

As an example; assume that we have a shared integer object called x, and we have two threads 1, and 2. Thread number 1 attempt to increment the x object by one, and during this increment process, its time slice has been finished. Thread 2 time slice just start and it attempt to increment the same x object too. Thread 2 incremented the x object successfully, and then its time slice finished. Thread 1 starts a new time slice and completing the increment process not knowing that the object x value is already changed. This is a race condition, and the output of such code is of course incorrect!

The above race condition problem can be solved by using an object like "InterLock", with its "Increment", and "Decrement" methods.

Race conditions can be avoided generally by considering each line of code you write, and asking yourself: What might happen if a thread finished before executing this line? or during executing this line? and another thread overtook it?
Submitted by: Administrator

Read Online .Net Architecture Job Interview Questions And Answers