cpdo

CpdoAndThreads
Login

CpdoAndThreads

ACHTUNG: THE CPDO WIKI IS NOW (AS OF 2011-May-17) MAINTAINED ON A DEDICATED WIKI SITE: http://whiki.wanderinghorse.net/wikis/cpdo/?page=CpdoAndThreads

The library's policies on multi-threaded operation are as follows...

It is never legal to use a single cpdo_stmt instance from more than one thread unless those threads use it serially (e.g. on prepares it and another one processes it). Concurrent access induces undefined behaviour. Statement handles tend to be very stateful, and concurrent access can easily lead to memory corruption or access to memory which was invalidated when one thread iterates the cursor and another thread just read results from the previous row.

Whether or not multi-threaded access to a cpdo_driver implementation is allowed depends on the driver. Even if a driver allows it, however, there are corner cases they cannot generically cover without specific infrastructure to support it, e.g. one thread is running a query and other closes the connection while the query is running. Again, undefined behaviour.

None of the current drivers have explicit support for multi-threaded use of the database driver. Both the cpdo_sqlite3 and cpdo_mysql5 drivers require some internal state in order to be able to implement the transaction-related APIs, so multi-threaded concurrent access to them is not allowed. Aside from that internal data, the drivers' only appreciable state is the underlying db connection object. sqlite3 supports (with the compile-time options) multi-threaded use of a db connection, but i have no idea if MySQL does.