perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <>
Subject Re: [mp2] Our API is not perl thread-safe
Date Tue, 22 Mar 2005 22:34:30 GMT
Stas Bekman wrote:
> As I've suspected our API is not perl thread-safe (note that perl's 
> thread-safe definition and the general thread-safe concept have little 
> to do with each other). I've started writing some tests and it's 
> segfaults all over.

Here is a very trivial test, which segfault:

#!perl -T

use strict;
use warnings FATAL => 'all';

use threads;

use APR::Pool ();

use Config;
use constant THREADS_OK => $] >= 5.008 && $Config{useithreads};
die "perl w/ ithreads is required" unless THREADS_OK;

our $p = APR::Pool->new;
my $threads = 2;

threads->new(sub {}) for 1..$threads;

$_->join() for threads->list();


here $p is cloned by perl twice (2 threads started), so now we have 3 perl 
objects all pointing at the same APR pool. Obviously at the end of script, 
each is trying to destroy the pool. The first succeeds, the next two 
segfault (in fact I've observed that only the third segfaults). Note that 
it's not enough to somehow mark the clones as not destructable. Even if we 
avoid the crash at the shutdown, we now get into the real C 
thread-safeness where the same pool object will be accessed by various 
threads w/o any locking. And even if we add locking, the parent thread may 
go out of scope before the child threads (which can be detached), in which 
case the carpet will be pulled from under all the objects created from 
that pool....

Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker     mod_perl Guide --->

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message