View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Philip Gwyn > Tie-Concurrent-0.05 > Tie::Concurrent



Annotate this POD

View/Report Bugs
Module Version: 0.05   Source  


Tie::Concurrent - Paranoid tie for concurrent access


    use Tie::Concurrent;
    tie %data, 'Tie::Concurrent', {READER=>[....], WRITER=>[....]};


Modules like GDBM_File are fraught when you have potentialy many readers/writers (like say in a long running forking daemon). While they might handle file locking properly, if any program holds the lock for too long, others will not be able to write to the file.

This module solves the problem by doing a tie/operation/untie for each and every operation. NOTE THAT THIS IS ONE HUGE PERFORMANCE HIT. Only use this where all other methods fail.

The params to tie are :


Array ref that is used to tie the underlying hash when only reading is desired.


Array ref that is used to tie the underlying hash when writing is needed.


    use Tie::Concurrent;
    use GDBM_File;
    use Storable;
    use MLDBM qw(GDBM_File Storable);

    my $file="search-cache.gdbm";

    my %cache;
    tie %cache, 'Tie::Concurrent', {
            READER=>['MLDBM', $file, GDBM_READER, 0660], 
            WRITER=>['MLDBM', $file, GDBM_WRCREAT, 0660]

    my $res=$cache{$key};
    unless($res) {
    print "\n", @$res;


Please note that there are many problems with this aproach. For instance, in the above example, another process might have created $cache{$key} while we did our search and those values would be lost.

If a process tries to lock the file whist another already has the lock, we wait one second before trying again. This is not very friendly if to things like POE.

In fact, the truth is that Tie::Concurrent does locking only if the underlying object does locking. If you an AnyDBM_File which doesn't lock, Tie::Concurrent isn't safe. All it will gain you is that results are automatically flushed each fetch/store.


FIRSTKEY/NEXTKEY not implemented yet.

MLDBM spits out warnings if it can't tie the file.

MLDBM::DELETE is broken. It does not return the deleted value.


Philip Gwyn, <>


Copyright (C) 2009 by Philip Gwyn

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.


perl(1). perltie(1)

syntax highlighting: