On Tue, 20 Mar 2001, Perrin Harkins wrote:

> On Wed, 21 Mar 2001, Stas Bekman wrote:
> > > You mean with DB_File?  There's a big warning in the current version
> > > saying not to do that, because there is some initial buffering that
> > > happens when opening a database.
> >
> > The warning says not to lock on dbm fd but an external file!
>
> I think you'll still have problems with this technique, unless you
> tie/untie every time.  I'm looking at the perldoc for DB_File version
> 1.76, at the section titled "Locking: the trouble with fd".  At the very
> least, you'd have to call sync after acquiring a write lock but before
> writing anything.

Of course, you always call sync. The sync was always there, even with the
flawed locking scheme. The DB_File doc was updated as a follow up of the
research done by David Harris. This should work:

flock SH
tie()
read...
flock EX <===== start critical section
write...
sync()
flock SH <===== end critical section
read...
untie()
flock UN

notice that the locking is done on the *external* file (or fd).

The only problem in this approach is a possible writing starvation as
explained:
http://perl.apache.org/guide/dbm.html#Locking_dbm_Handlers_and_Write_L

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Reply via email to