home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl560.zip / ext / Thread / list.t < prev    next >
Text File  |  1999-07-20  |  677b  |  31 lines

  1. use Thread qw(async);
  2. use Thread::Semaphore;
  3.  
  4. my $sem = Thread::Semaphore->new(0);
  5.  
  6. $nthreads = 4;
  7.  
  8. for (my $i = 0; $i < $nthreads; $i++) {
  9.     async {
  10.          my $tid = Thread->self->tid;
  11.     print "thread $tid started...\n";
  12.     $sem->down;
  13.     print "thread $tid finishing\n";
  14.     };
  15. }
  16.  
  17. print "main: started $nthreads threads\n";
  18. sleep 2;
  19.  
  20. my @list = Thread->list;
  21. printf "main: Thread->list returned %d threads\n", scalar(@list);
  22.  
  23. foreach my $t (@list) {
  24.     print "inspecting thread $t...\n";
  25.     print "...deref is $$t\n";
  26.     print "...flags = ", $t->flags, "\n";
  27.     print "...tid = ", $t->tid, "\n";
  28. }
  29. print "main thread telling workers to finish off...\n";
  30. $sem->up($nthreads);
  31.