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

  1. use Thread;
  2.  
  3. use Thread::Specific qw(foo);
  4.  
  5. sub count {
  6.     my $tid = Thread->self->tid;
  7.     my Thread::Specific $tsd = Thread::Specific::data;
  8.     for (my $i = 0; $i < 5; $i++) {
  9.     $tsd->{foo} = $i;
  10.     print "thread $tid count: $tsd->{foo}\n";
  11.     select(undef, undef, undef, rand(2));
  12.     }
  13. };
  14.  
  15. for(my $t = 0; $t < 5; $t++) {
  16.     new Thread \&count;
  17. }
  18.