delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/11/09/12:21:54

From: amb AT gedanken DOT demon DOT co DOT uk (Andrew M. Bishop)
Subject: Atomic UNIX operations transferred to Win32
9 Nov 1998 12:21:54 -0800 :
Message-ID: <E0zcRP3-0001lV-00.cygnus.gnu-win32@gedanken.demon.co.uk>
To: gnu-win32 AT cygnus DOT com

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                             amb AT gedanken DOT demon DOT co DOT uk
                                      http://www.gedanken.demon.co.uk/
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019