TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:5462] "Race Condition"?



schewe@tcfreenet.org wrote:
> 
> On 21 Apr, Michael Hicks wrote:
> > I was wondering if someone could explain to me exactly what a 'race condition'
> > is.  I've heard about it many times, but the context is usually weak and I can't
> > quite figure it out.
> >
> It has to do with multiple processes sharing memory.  One common one is
> this:
> process 1 reads memory address 400 and gets the number 4 from it.
> process 2 ready memory address 400 and gets the number 4
> process 1 says that 4 is bad and 5 should be in there.  So it puts 5 in
> memory address 400.
> process 2 says 4 is good and so puts 4 back in memory address 400.
> 
> This is a very simple example of a race condition.  You should only
> have to worry about it when using threads, or other concurrent
> programming.
> 

- Well it can be any shared resource not neccessarily memory. It
  could be a harddisk, or a serial port, or a mouse.
- It does not have to be processes in software, it can be hardware
  mechanical  or electrical or chemical processes even.

It happens when more than 1 person/task/machine try to access
the same resource or item simultaneously when they should actually
use it one after the other.  Two people rushing to use the bathroom
at the same time and getting stuck at the door is also an example
of a race condition !  

In software and hardware that has to work concurrently it is
very important that we serialize access to these shared resources
and make sure that the right task/program gets hold of the resource
at the right time. 

Hope this helps !
--
sandipan