Autoflush for DB_FILE to share a hash among cooperating processes?

Discussion in 'Perl Misc' started by Axel Boldt, Apr 7, 2004.

  1. Axel Boldt

    Axel Boldt Guest

    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
    Axel Boldt, Apr 7, 2004
    #1
    1. Advertising

  2. Axel Boldt

    Dan Wilga Guest

    In article <>,
    (Axel Boldt) wrote:

    > 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.

    --
    Dan Wilga
    ** Remove the -MUNGE in my address to reply **
    Dan Wilga, Apr 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. red floyd
    Replies:
    1
    Views:
    474
    Zhang Yan
    Sep 6, 2003
  2. Vasko Altiparmakov

    cooperating & nested classes

    Vasko Altiparmakov, Mar 8, 2004, in forum: C++
    Replies:
    1
    Views:
    494
    Claudio Puviani
    Mar 8, 2004
  3. schnitzell

    Webservice cooperating with any database.

    schnitzell, Aug 31, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    121
    Michael Nemtsev
    Aug 31, 2005
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,287
    Saraswati lakki
    Jan 6, 2012
  5. James

    DB_File (hash of array) problem

    James, Jun 22, 2010, in forum: Perl Misc
    Replies:
    5
    Views:
    150
    Xho Jingleheimerschmidt
    Jun 23, 2010
Loading...

Share This Page