This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
A configuration system for VMS perl
[perl5.git] / ext / Thread / Thread / Queue.pm
CommitLineData
d21067e0
MB
1package Thread::Queue;
2use Thread qw(cond_wait cond_broadcast);
3
d516a115
JH
4=head1 NAME
5
6Thread::Queue - thread-safe queues
7
8=head1 SYNOPSIS
9
10 use Thread::Queue;
11 my $q = new Thread::Queue;
12 $q->enqueue("foo", "bar");
13 my $foo = $q->dequeue; # The "bar" is still in the queue.
14
15=cut
16
d21067e0
MB
17sub new {
18 my $class = shift;
19 return bless [@_], $class;
20}
21
22sub dequeue {
23 use attrs qw(locked method);
24 my $q = shift;
25 cond_wait $q until @$q;
26 return shift @$q;
27}
28
29sub enqueue {
30 use attrs qw(locked method);
31 my $q = shift;
32 push(@$q, @_) and cond_broadcast $q;
33}
34
351;