Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!yale!cmcl2!panix!alexis From: alexis@panix.UUCP (Alexis Rosen) Newsgroups: comp.databases Subject: Re: rlock() in SCO foxbase+. Keywords: foxbase, rlock Message-ID: <10499@panix.UUCP> Date: 25 Sep 90 06:45:17 GMT References: <553@safn2.UUCP> Organization: PANIX - Public Access Unix Systems of NY Lines: 53 I know it can be confusing, but I'd suggest that you RTFM, two times. briefly: The *PROGRAM* (which is to say, the pid in unix) owns locks. However, you can't use rlock to append. It's a really stupid way to do things, but the only way to append in multi-user is: 1) Obvious but slow- Flock() the file, and if you get the lock, append and release. 2) Fast and ugly- just do append blank. If you can't make the record, it'll generate an error. Catch the error in your error-handling routine (you do have one, right?) This becomes enourmously easier if you encapsulate the Append routine. Here's mine, for Fox/Mac, which should work identically: * DelayAppnd(secs) * Try up to 'secs' seconds to append a blank record. * Relies on the error-handling routine to set appenderr to .F. if the * append fails. Returns .T. if append succeeded, .F. if not Param secs && number of seconds to wait Priv appenderr && semaphore flipped by Error-handler if append fails Priv t && ending time Priv junk t = Val(Sys(2))+secs Do While (Val(Sys(2)) <= t) appenderr = .F. && no error condition yet this pass in loop Append Blank && give it a shot If appenderr && if append failed, the error-handler set this junk = Inkey(1) && wait a second so we don't thrash the DBMS Else appenderr = !Rlock() && We don't get a lock on a record && just by creating it Exit Endif Enddo && loop for 'secs' seconds or until we achieve a lock Return !appenderr ----- Remeber to look for the specific error number for a "failed to append" in B your error-trapping routine. Also, don't forget to release any lock you create. Generally speaking you shouldn't hold on to locks for more than a fraction of a second- no reason. Unlike dBase IV and FoxPro, you can only have ONE lock at a time- I think. There's some small possibility that the unix version is different. Hope this helps, --- Alexis Rosen cmcl2!panix!alexis