finding ....

Jon Fairbairn
Wed, 20 Mar 2002 10:18:56 +0000

> Could someone post an example of the creation of a
> temporary file where race conditions are important?

/any/ programme that does this on a multi-process system.

Between the test for existence and the creation, some other
process could have created a file of the same name. Then
the create fails because of insufficient permissions,
so the programme has to deal with failure anyway, or it
succeeds and stomps on the data belonging to the other

do possible_handle <- try $ openFile "whatever" ReadMode
   case possible_handle =

     of (Right handle) -> do_things_to handle
        (Left error) -> do whatever you would have done had
                           the existence test returned false

is no more complex than a version using an existence test,
but to create a file for writing, surely we need an
openNewFile primitive? Otherwise we might open on a file
that already exists and hit the "stomp" error mentioned


-- =

J=F3n Fairbairn                       
31 Chalmers Road                               
Cambridge CB1 3SZ            +44 1223 570179 (after 14:00 only, please!)