Subject: Atomic UNIX operations transferred to Win32
From: [email-masked] (Andrew M. Bishop)

9 Nov 1998 12:21:54 -0800
Message-ID: <[email-masked]>
To: [email-masked]

I have a question about operations that are atomic under UNIXs when
they are transferred to Win32.

By atomic I mean that there is no context switch possible between
calling the function and it returning.  Examples would be link(),
unlink(), rename() etc.

The link() system call on Win95/98 is done by making a copy of the
file (in the FAQ).  I would guess that this operation is not atomic
(it could take a long time) and that if there are two processes there
could be a race condition.

Example:

Process 1 looks for files called foo.* and link()s them to bar.*.
Process 2 unlink()s foo.* if bar.* exists.

Then process 2 could unlink a file that process 1 is still copying,
can you confirm if this is the case and if the other operations are
atomic.

Another problem that I came across while porting a program is that the
following code does not work.

int fd=-1;
while(ent=readdir(dir))
  {
   fd=open(ent->d_name,...);
   if(fd!=-1)
     {
      if(unlink(ent->d_name))
        {close(fd);fd=-1;}
      else
         break;
     }
  }

The file is not deleted while it is open, this means that the second
process will also find the same file and open() it and unlink() it
succesfully.

I discovered the problem with beta-19 and re-coded it (to use rename
rather than unlink) before using beta-20, so I can't be 100% sure that
it still exists.

Finally, a minor problem with make under beta-20

-------------------- Makefile --------------------
foo:
        @true
-------------------- Makefile --------------------

This fails because it can't execute the true command, it does work
from the command line though.

-- 
Andrew.
----------------------------------------------------------------------
Andrew M. Bishop                             [email-masked]
                                      http://www.gedanken.demon.co.uk/
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".