1

スレッドを作成する前にreaddirを呼び出すと、次のようなエラーが発生します。

perl(2820,0x7fff70c33ca0) malloc: *** error for object 0x10082e600: pointer 
being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap

奇妙なことに、スレッドを作成する前にreaddirを呼び出すと発生します(つまり、readdirはどの並行コードでも呼び出されません)。readdirの結果も使用していません。呼び出しを行うだけで、問題が発生するようです。私がそれを取り除くとき、物事はうまくいくようです。いくつかのサンプルコードを以下に示します。

opendir(DIR, $someDir);
my @allFiles = readdir(DIR);
close(DIR);

my $thread = threads->create(\&sub1);
$thread->join();

sub sub1 {
print "in thread\n"
} 
4

2 に答える 2

4

You need to use closedir, not close, to close a directory handle. Fixing that makes this work correctly, though the symtom I see with close() is a little different:

*** glibc detected *** perl: double free or corruption (!prev): 0x09bc7d28 ***

However, this should still be reported as a bug, since it should be perfectly ok to leave the directory handle to be automatically closed at the end of the program.

于 2010-12-26T04:25:12.953 に答える
0

最新 (または 2 つ) の開発バージョンまでのすべてのバージョンの perl でディレクトリハンドルを開くと問題が発生します - この問題は最近修正されました。

PS レキシカル dirhandles を使用します。

于 2010-12-26T11:09:25.780 に答える