Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with dequeue

Status
Not open for further replies.

bojandardic

Programmer
Joined
Dec 18, 2006
Messages
2
Location
BA
I have this perl script with additional thread "read_pipe" that read data from fifo pipe and enqueue that data to queue. On other end this data from queue should be read in main thread. Reading data from pipe and puting it on queue is OK, but main thread never get this data.

Why dequeue do not work?

I use openSuse 10.0 with installed perl 5.8.8.

Script:
#!/usr/local/bin/perl

use strict;
use Thread;
use Thread::Queue;

my $queue = new Thread::Queue;
my $read_pipe_thread = new Thread(\&read_pipe, $queue);
my $queue_read;
while (1) {
$queue_read = $queue->dequeue;
print "queue=" . $queue_read . "\n";
if ($queue_read eq "quit") {
print "quit program\n";
exit;
}
}
$queue->enqueue(undef);

sub read_pipe {
my ($queue) = @_;
my $fifo = '.fifo_pipe';
if (!(-e $fifo)) {
system('mkfifo', $fifo);
}
my $data;
open(FIFO, "+< $fifo") or die $!;
print "pipe opened\n";
while(<FIFO>) {
chomp($data = $_);
print "pipe=" . $data . "\n";
$queue->enqueue($data);
if ($data eq "quit") {
close(FIFO);
}
}
print "pipe closed\n";
if (-e $fifo) {
system('rm', $fifo);
}
}

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top