POV-Ray : Newsgroups : povray.programming : Portable Mutex for POV? : Portable Mutex for POV? Server Time
28 Jul 2024 20:24:23 EDT (-0400)
  Portable Mutex for POV?  
From: Nigel Stewart
Date: 14 Jul 1999 05:03:09
Message: <378C441A.F871EE92@eisa.net.au>
I've been thinking about how to support distributed
rendering with POV, without having to introduce
any platform specific code.  What I have at the
moment is a Mutex implementation, based on
a lock file.

Imagine a LAN with a common filesystem, and 
povray running on different machines.  Each
povray looks in the same directory for INI
files, a queue of jobs for the network.
There needs to be a mechanism to stop two
or more povray's grabbing the same INI.

What I have at the moment is a lock file
that is owned by only one process at a time.
The implementation is attached to the end
of this post.  The basic idea is to use
the remove() standard ANSI C function to 
test if any other process has a lock on the
resource.  It will also fail in the situation
where another process has removed the file,
but hasn't yet replaced it.

It works in Windows NT, I'm going to try it
on Linux....  But does anyone have a general
impression whether this is going to work
across network filesystems: Windows, Novell,
NFS?  

Also, is there a tider way to do this?
A weakness in the algorithm is that if
the file is missing, no process will be
able to lock the resource.  Therefore,
I'm not happy with the robustness of
this particular algorithm.

----

FILE *lockFile = NULL;

void unlock()
{
  if (lockFile)
    fclose(lockFile);
} 

void lockDir(const char *dir)
{
  char filename[MAXPATH];
  sprintf(filename,"%s/lock.tmp",dir);

  unlock();
  while (remove(filename)!=0)
	  Wait(2);
  
  lockFile = fopen(filename,"w");
}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.