I apologize if this appears twice. I posted it once and did not see it
appear (after waiting a few hours) in the list so I'm posting it again.

I'm looking at the source code for queue.pm and I'm quite surprised at how
short it is. I have some questions about the syntax: 

 

(1)     What does this colon (": shared") mean on line 69? I have not seen a
colon used like this before.

 

  67 sub new {
  68     my $class = shift;
  69     my @q : shared = @_;
  70     return bless [EMAIL PROTECTED], $class;
  71 }

 

(2)     From the main program, I'm calling "my $Q = Thread::Queue->new();".
Now there are no arguments except $class. What does @q get? An empty array?

(3)     What are we pushing on here on line 90? I don't see an array defined
anywhere. When we bless an object, we basically have hash table, correct?
How is it that we are allowed to push on a hash table? Is it legal to bless
an array instead of a hash table?

 

  87 sub enqueue {
  88     my $q = shift;
  89     lock(@$q);
  90     push @$q, @_  and cond_signal @$q;
  91 }

 

(4)     I wish I knew why this code does not work. It is so simple. There
must be a bug in line 76 because it never returns from a call to dequeue. Do
you suppose this means there is a bug in the implementations of cond_wait
for 5.8 of ActiveState perl? When I discovered that my code was not working
correctly, I typed in the code from Larry Wall's "Programming Perl" and that
did not work either. Both my code and Larry's hang on this dequeue function,
even when there is something in the queue.

  73 sub dequeue  {
  74     my $q = shift;
  75     lock(@$q);
  76     cond_wait @$q until @$q;
  77     cond_signal @$q if @$q > 1;
  78     return shift @$q;
  79 }

 

Thanks,

Siegfried


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to