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

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



On Wed, 21 Apr 1999, 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.
> 
> Thanks..
> -- 

The race condition happens in a reader/writer situation where reader and
writer are running concurrently.  Let's say they read and write from
buffer.  The programs look like this: 

#writer
overwrite buffer with new contents
signal reader that data is available

#reader
read buffer
signal writer that buffer has been read and can now be overwritten

If there is an error in which reader reads twice before writer writes, or
if writer writes twice before reader reads, the signals have happened out
of order, or maybe they did not happen.  If reader or writer are too eager
to get, or write, the data, that's the race.