今まで問題が出なかったので気付かなかったのですが、
thread オブジェクトは join() で終了させただけでは、
プロセス内にいろいろ影響を出すようです。
#!/usr/bin/env perl
use strict;
use threads;
sub _thread_main()
{
sleep(1);
}
# main routine.
my $fname = "tmp.dat";
open(FH, "> $fname");
my $th = threads->new(\&_thread_main);
$th->join();
close(FH);
unlink($fname);
この code を実行すると、tmp.dat ファイルが作成されたまま残ってしまいます。
これを改善するためには undef $th; を $th->join() の後ろのどこかで実行します。
具体的な挙動は調べきれなかったのですが、終了した thread であっても、
reference counter などに影響を与えているような感じがします。
とりあえず、終了が確認された thread オブジェクトは
さっくり消してしまうのが一番のようです。
@
こんなのも見つけた:
XML::Parser と encoding が指定されている xml file と thread は
食べ合わせが本格的に悪いようです。
#!/usr/bin/env perl
use strict;
use threads;
use XML::Parser;
sub dummy_handler($$)
{
}
sub _thread_main()
{
sleep(1);
}
# main routine.
my $parser = new XML::Parser();
$parser->parsefile("target.xml");
my $th = threads->new(\&_thread_main);
$th->join();
undef $th;
というスクリプトに encoding 付きの xml file を食べさせると SEGV で落ちます。
% cat target.xml
<?xml version="1.0" encoding="x-euc-jp-unicode"?>
<test/>
% perl sample.pl
Segmentation fault
不思議なことに、encoding の指定をはずすと落ちなくなります。
% cat target.xml
<?xml version="1.0"?>
<test/>
% perl sample.pl
%
こっちは原因は全然分かりません(^^;
ActivePerl では次のメッセージが出力されるので、
これがキーになるとは思うのですが今はちょっと手が出せない…。
Free to wrong pool 1b35270 not 1623ff8 at C:/Perl/site/lib/XML/Parser/Expat.pm l
ine 655 during global destruction.