Thread†
thread の生成†
queue による通信†
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;
thread 間で共有する変数†
- thread 間で共有したい変数は、その旨明示的に宣言する必要がある。
use threads;
use threads::shared; # thread 間で共有するデータを扱う
my <thread間共有変数> : shared = <初期化値>;
- 例
use threads;
use threads::shared; # thread 間で共有するデータを扱う
my $data : shared = 2; # 変数を初期化する値は、 ": shared" に続けて代入する
my @datas : shared = ();