isolating thread-unsafe modules

Bob MacCallum uncoolbob at
Sun Jul 28 20:07:59 BST 2013

Sorry for the Perl question, but I'm a bit out of my depth...

I have a Dancer app providing a web service, and I have another script
using the same Dancer config file and db schema (e.g. "use Dancer
qw/:script/").  This script watches the database (for changes made by the
web app) and does the "heavy lifting".  Now I want to parallelise the heavy
lifting with threads and it seems from the core dump and googling that
DBD::Pg is not thread safe (see the few lines of debugger output below).

That's fine - I am happy to run only non-database code in my "worker
threads".  The trouble is that even if I do this, I think the
threads->create is threading the Dancer globals which include postgres
schema connections.

I tried a few "no My::Schema; no DBD::Pg; no Dancer ..." declarations in
the block with the threads->create - but that didn't seem to help.

Does anyone know how I can use thread-safe and thread-unsafe code in the
same script?  I think I just need to make a block where none of the
Dancer/database stuff is in scope?

I thought Thread::Isolate might help, but it hangs on the first test during
the install.  It's dated 2005.


Reading symbols from
Loaded symbols for .../perl5/x86_64-linux-thread-multi/auto/DBD/Pg/
Reading symbols from
/usr/local/pgsql_dir/postgresql-8.4.7/lib/ debugging
symbols found)...done.
Loaded symbols for /usr/local/pgsql_dir/postgresql-8.4.7/lib/
Core was generated by `perl bin/'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007f9de39e923e in PerlIOEncode_getarg () from

More information about the mailing list