home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / Thread::Queue.Z / Thread::Queue
Encoding:
Text File  |  1998-10-28  |  3.5 KB  |  133 lines

  1.  
  2.  
  3.  
  4.      TTTThhhhrrrreeeeaaaadddd::::::::QQQQuuuueeeeuuuueeee((((3333))))22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222)))) TTTThhhhrrrreeeeaaaadddd::::::::QQQQuuuueeeeuuuueeee((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       Thread::Queue    - thread-safe queues
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.           use Thread::Queue;
  13.           my $q = new Thread::Queue;
  14.           $q->enqueue("foo", "bar");
  15.           my $foo =    $q->dequeue;    # The "bar" is still in    the queue.
  16.           my $foo =    $q->dequeue_nb;    # returns "bar", or undef if the queue was
  17.                     # empty
  18.           my $left = $q->pending;    # returns the number of    items still in the queue
  19.  
  20.  
  21.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  22.       A queue, as implemented by Thread::Queue is a    thread-safe
  23.       data structure much like a list. Any number of threads can
  24.       safely add elements to the end of the    list, or remove
  25.       elements from    the head of the    list. (Queues don't permit
  26.       adding or removing elements from the middle of the list)
  27.  
  28.      FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNNSSSS AAAANNNNDDDD MMMMEEEETTTTHHHHOOOODDDDSSSS
  29.       new      The new function creates a new empty queue.
  30.  
  31.       enqueue LIST
  32.           The enqueue method adds a list of scalars on to the
  33.           end of the queue.  The queue will grow as needed to
  34.           accomodate the list.
  35.  
  36.       dequeue The dequeue method removes a scalar from the head of
  37.           the queue and    returns    it. If the queue is currently
  38.           empty, dequeue will block the    thread until another
  39.           thread enqueues a scalar.
  40.  
  41.       dequeue_nb
  42.           The dequeue_nb method, like the dequeue method,
  43.           removes a scalar from    the head of the    queue and
  44.           returns it. Unlike dequeue, though, dequeue_nb won't
  45.           block    if the queue is    empty, instead returning
  46.           undef.
  47.  
  48.       pending The pending method returns the number    of items still
  49.           in the queue.     (If there can be multiple readers on
  50.           the queue it's best to lock the queue    before
  51.           checking to make sure    that it    stays in a consistent
  52.           state)
  53.  
  54.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  55.       the _T_h_r_e_a_d manpage
  56.  
  57.       =cut
  58.  
  59.       sub new {
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      TTTThhhhrrrreeeeaaaadddd::::::::QQQQuuuueeeeuuuueeee((((3333))))22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222)))) TTTThhhhrrrreeeeaaaadddd::::::::QQQQuuuueeeeuuuueeee((((3333))))
  71.  
  72.  
  73.  
  74.           my $class    = shift;
  75.           return bless [@_], $class; }
  76.  
  77.       sub dequeue {
  78.           use attrs    _q_w(locked method);
  79.           my $q = shift;
  80.           cond_wait    $q until @$q;
  81.           return shift @$q;    }
  82.  
  83.       sub dequeue_nb {
  84.         use    attrs _q_w(locked    method);
  85.         my $q = shift;
  86.         if (@$q) {
  87.           return shift @$q;
  88.         } else {
  89.           return undef;
  90.         } }
  91.  
  92.       sub enqueue {
  93.           use attrs    _q_w(locked method);
  94.           my $q = shift;
  95.           _p_u_s_h(@$q,    @_) and    cond_broadcast $q; }
  96.  
  97.       sub pending {
  98.         use    attrs _q_w(locked    method);
  99.         my $q = shift;
  100.         return _s_c_a_l_a_r(@$q);    }
  101.  
  102.       1;
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.