| Refresh | Home EGTry.com

get thread id


use threads;

printid("main");

my $t=threads->create(\&printid,"child");
$t->join();

$t=threads->create(\&printid, "child");
$t->join();

$t=threads->create(\&printid, "child");
$t->join();

sub printid {
  my $name=shift;
  my $t=threads->self();
  my $tid=$t->tid();

  print "$name thread id: $tid\n";
}



Output

main thread id: 0
child thread id: 1
child thread id: 2
child thread id: 3