I just looked at the DBI::FAQ, and there it says:
The DBI, as of version 1.02, does not yet support multi-threading so it would be unsafe to let more than one thread enter the DBI at the same time.
It is expected that some future version of the DBI will at least be thread-safe (but not thread-hot) by automatically blocking threads intering the DBI while it's already in use.
So the answer is no. Your program can have at most one DBI instance alive ("the brain").
Update: perrin points out that my information is old and not completely correct anymore - DBI will try its best and clone every database handle that was created before a thread was spawned, and it will even try its best to prevent you from sharing a database handle across thread boundaries. But there still is the caveat:
But BEWARE, some underlying database APIs (the code the DBD driver uses to talk to the database, often supplied by the database vendor) are not thread safe. If it's not thread safe, then allowing more than one thread to enter the code at the same time may cause subtle/serious problems. In some cases allowing more than one thread to enter the code, even if not at the same time, can cause problems. You have been warned.
Using DBI with perl threads is not yet recommended for production environments. For more information see Things you need to know before programming Perl ithreads
So, the "best" solution is to either have one thread to handle the database connection, or one or more external processes that connect to the database(s).
In reply to Re^3: DBI and threads
by Corion
in thread DBI and threads
by fd15k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |