Top/Lang/Perl/thread

目次

Thread

thread の生成

use threads;

# thread の生成
my ($thread_1) = threads->new(\&thread_func, "t1");

# thread 終了の待ち合わせ
$thread_1->join;

# thread 関数
sub thread_func {
    # 処理
}

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;

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS