use threads;
# thread の生成
# スレッド関数を new の第1引数に、スレッド関数に渡す引数を第2引数以降に指定する。
my ($thread_1) = threads->new(\&thread_func, "t1");
# thread 終了の待ち合わせ
$thread_1->join;
# thread 関数
sub thread_func {
# 処理
}use threads; use Thread::Queue; my ($queue_a) = new Thread::Queue; # thread 生成時に、 thread 関数の引数として Queue を渡す: my ($thread_a) = threads->new(\&thread_func_a, $queue_a); $thread_a->join;
$queue_a->enqueue(<データ>);
$data = $queue_a->dequeue();
use threads; use threads::shared; # thread 間で共有するデータを扱う my <thread間共有変数> : shared = <初期化値>;
use threads; use threads::shared; # thread 間で共有するデータを扱う my $data : shared = 2; my @datas : shared = ();