[Xapian-discuss] Perl threads and Xapian - incompatibility?

Ron Kass ron at pidgintech.com
Fri Oct 19 04:54:07 BST 2007


> So it looks like the new interpreter for each thread makes a new Perl
> Search::Xapian::Database object, but wrapped around the same C++
> Xapian::Database object inside.  That's never going to work well!
>
> I've no idea how to fix this (or if it is fixable even), but you have a
> workaround.
>
> Cheers,
>     Olly
>   
Actually I've found something here...
http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlmod.pod#Making_your_module_threadsafe_________

Perl after 5.8.7 has support for the |CLONE_SKIP| special subroutine. 
Like |CLONE|, |CLONE_SKIP| is called once per package; however, it is 
called just before cloning starts, and in the context of the parent 
thread. If it returns a true value, then no objects of that class will 
be cloned; or rather, they will be copied as unblessed, undef values. 
This provides a simple mechanism for making a module threadsafe; just 
add |sub CLONE_SKIP { 1 }| at the top of the class, and |DESTROY()| will 
be now only be called once per object. Of course, if the child thread 
needs to make use of the objects, then a more sophisticated approach is 
needed.

Your thoughts?

Ron


More information about the Xapian-discuss mailing list