This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
Atomic UNIX operations transferred to Win32
- To: gnu-win32 at cygnus dot com
- Subject: Atomic UNIX operations transferred to Win32
- From: "Andrew M. Bishop" <amb at gedanken dot demon dot co dot uk>
- Date: Sun, 8 Nov 1998 09:45:01 +0000
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@gedanken.demon.co.uk
http://www.gedanken.demon.co.uk/
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".