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

  1. use Thread;
  2.  
  3. $| = 1;
  4.  
  5. srand($$^$^T);
  6.  
  7. sub printargs {
  8.     my $thread = shift;
  9.     my $arg;
  10.     my $i;
  11.     while ($arg = shift) {
  12.     my $delay = int(rand(500));
  13.     $i++;
  14.     print "$thread arg $i is $arg\n";
  15.     1 while $delay--;
  16.     }
  17. }
  18.  
  19. sub start_thread {
  20.     my $thread = shift;
  21.     my $count = 10;
  22.     while ($count--) {
  23.     my(@args) = ($thread) x int(rand(10));
  24.     print "$thread $count calling printargs @args\n";
  25.     printargs($thread, @args);
  26.     }
  27. }
  28.  
  29. new Thread (\&start_thread, "A");
  30. new Thread (\&start_thread, "B");
  31. #new Thread (\&start_thread, "C");
  32. #new Thread (\&start_thread, "D");
  33. #new Thread (\&start_thread, "E");
  34. #new Thread (\&start_thread, "F");
  35.  
  36. print "main: exiting\n";
  37.