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?

References:-
http://www.developerfusion.co.uk/show/4134/5/
http://www.beansoftware.com/ASP.NET-Tutorials/Manual-Synchronize-Thread.aspx

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: Race Condition: an issue in ASP.Net

That was an inspiring post,

this is why I hate to use threads predicting it's behaviour is not always easy
Thanks 8/19/2009 10:19 AM | web development company

Post a comment





 

 

News

Employers
Soppa Group India
iSmart Panache Inc
R Systems Internationals Ltd
Technovate eSolutions Pvt Ltd
The contents of this blog are my personal opinion and do not represent in any way the view of my employer.
These postings are provided "AS IS" with no warranties, and confer no rights.

Google PR™ - Post your Page Rank with MyGooglePageRank.com

Archives

Post Categories

Image Galleries

Articles & Magazines

ASP.Net 2.0 Compilation

ASP.Net, Blogs I refer...

Atlas

Dost

Drivers and Software Download

Garhwal

Travel Domain

WSS and WebParts

Syndication: