#!/usr/bin/perl use strict; use threads; use threads::shared; use Thread::Queue; use DB_File::Lock; use Fcntl; my $q = Thread::Queue->new(); my %items; my $DB = tie %items,'DB_File::Lock','itemdb',O_CREAT|O_RDWR,0640,$DB_HASH,'write' or die "Could not open SDBM file: $!\n"; $items{$_} = 1 for 1..10; untie %items; undef $DB; for (1..3) { threads->new(\&ttest) } my @threadlist = threads->list; $q->enqueue($_) for 1..10; $q->enqueue(undef) for @threadlist; $_->join for @threadlist; unlink 'itemdb.pag','itemdb.dir'; sub ttest { my %db; while (my $qthingie = $q->dequeue) { my %items; my $DB = tie %items,'DB_File::Lock','itemdb',O_CREAT|O_RDWR,0640,$DB_HASH,'write' or die "Could not open SDBM file: $!\n"; print "$qthingie $items{$qthingie}\n"; untie %items; } }