Advertisement
Guest User

Untitled

a guest
Jan 7th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. # from man perlthrtut merged with Camel 3rd example
  2. # (according to book Thread::Queue is build on cond_wait)
  3.  
  4. use threads;
  5. use Thread::Queue;
  6.  
  7. my $Q = Thread::Queue->new();
  8.  
  9. my $thr = threads->create(sub {
  10. while (my $el = $Q->dequeue()) {
  11. print("Popped $el off the queue\n");
  12. }
  13. });
  14.  
  15. $Q->enqueue(12);
  16. $Q->enqueue("A", "B", "C");
  17. sleep(3);
  18. $Q->enqueue(\%ENV);
  19. $Q->enqueue(undef);
  20. $thr->join();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement