race condition
race condition
[′rās kən‚dish·ən]race condition
For example, if one process writes to a file while another isreading from the same location then the data read may be theold contents, the new contents or some mixture of the twodepending on the relative timing of the read and writeoperations.
A common remedy in this kind of race condition is file locking; a more cumbersome remedy is to reorganize the systemsuch that a certain processes (running a daemon or the like)is the only process that has access to the file, and all otherprocesses that need to access the data in that file do so onlyvia interprocess communication with that one process.
As an example of a more subtle kind of race condition,consider a distributed chat network like IRC, where auser is granted channel-operator privileges in any channelhe starts. If two users on different servers, on differentends of the same network, try to start the same-named channelat the same time, each user's respective server will grantchannel-operator privileges to each user, since neither willyet have received the other's signal that that channel hasbeen started.
In this case of a race condition, the "shared resource" is theconception of the state of the network (what channels exist,as well as what users started them and therefore have whatprivileges), which each server is free to change as long as itsignals the other servers on the network about the changes sothat they can update their conception of the state of thenetwork. However, the latency across the network makespossible the kind of race condition described. In this case,heading off race conditions by imposing a form of control overaccess to the shared resource -- say, appointing one server tobe in charge of who holds what privileges -- would meanturning the distributed network into a centralized one (atleast for that one part of the network operation). Where thisis not acceptable, the more pragmatic solution is to have thesystem recognize when a race condition has occurred and torepair the ill effects.
Race conditions also affect electronic circuits where thevalue output by a logic gate depends on the exact timing oftwo or more input signals. For example, consider a two inputAND gate fed with a logic signal X on input A and itsnegation, NOT X, on input B. In theory, the output (X AND NOTX) should never be high. However, if changes in the value ofX take longer to propagate to input B than to input A thenwhen X changes from false to true, there will be a briefperiod during which both inputs are true, and so the gate'soutput will also be true. If this output is fed to anedge-sensitive component such as a counter or flip-flop thenthe temporary effect ("glitch") will become permanent.