From aed6f30b38100ba5d72978f485cb26a4dc6f8694 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Sun, 6 Jun 2010 20:24:41 -0700 Subject: [PATCH] cleaned up the end-of-streaming logic --- feedGnuplot.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/feedGnuplot.pl b/feedGnuplot.pl index 6f83e9e..7a20505 100755 --- a/feedGnuplot.pl +++ b/feedGnuplot.pl @@ -6,6 +6,7 @@ use IO::Handle; use List::MoreUtils qw( first_index ); use Data::Dumper; use threads; +use threads::shared; use Thread::Queue; open(GNUPLOT_VERSION, "gnuplot --version |"); @@ -175,6 +176,7 @@ my @curves = (); my $dataQueue; my $xwindow; +my $streamingFinished : shared = undef; if($options{"stream"}) { if( defined $options{"hardcopy"}) @@ -199,11 +201,10 @@ if($options{"stream"}) } } - $dataQueue->enqueue("Plot now"); - $dataQueue->enqueue(undef); + $streamingFinished = 1; - $addThr->join(); $plotThr->join(); + $addThr->join(); } else { @@ -214,11 +215,14 @@ else sub plotThread { - while(1) + while(! $streamingFinished) { sleep(1); $dataQueue->enqueue("Plot now"); } + + $dataQueue->enqueue(undef); + } sub mainThread {