Autoflush for DB_FILE to share a hash among cooperating processes?

A

Axel Boldt

Hello,

I want to share a hash variable among several forked processes.
Ideally I would use threads and threads::shared, but I need LWP which
is not thread-safe. So I thought about using DB_FILE and a hash
variable tied to the same file in each of the processes. If one
process changes the hash variable, all others should see the change
immediately. I.e. I want that the change is immediately flushed to
disk, and that every access to the hash variable takes its value
directly from disk, not from some internal cache. Is that possible? I
have tried the O_SYNC flag for db_open and also the $db->sync() method
to no avail.

If it's not possible, what do people usually do to keep a set of
cooperating processes informed about the results that the other
processes have already computed?

Thanks,
Axel
 
D

Dan Wilga

Hello,

I want to share a hash variable among several forked processes.
Ideally I would use threads and threads::shared, but I need LWP which
is not thread-safe. So I thought about using DB_FILE and a hash
variable tied to the same file in each of the processes. If one
process changes the hash variable, all others should see the change
immediately. I.e. I want that the change is immediately flushed to
disk, and that every access to the hash variable takes its value
directly from disk, not from some internal cache. Is that possible? I
have tried the O_SYNC flag for db_open and also the $db->sync() method
to no avail.

I would recommend using the BerkeleyDB module instead of DB_File, and
then using the DB_INIT_MPOOL and DB_INIT_CDB flags in a call to
BerkeleyDB::Env.

Anything less complex will lead to synchronization problems, since there
is no record locking in Berkeley DB, unless you use either CDB or full
transactional mode.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top