cpdo  Artifact Content

Artifact 37c15014150cdc8a2b2947b446d225e55715ef75:

Wiki page [CpdoAndThreads] by stephan 2011-05-17 18:39:27.
D 2011-05-17T18:39:27.562
L CpdoAndThreads
P f01ebcd38a2cfcfad6ea2ede79f412ceb919c05c
U stephan
W 1613
<strong>ACHTUNG: THE CPDO WIKI IS NOW (AS OF 2011-May-17) MAINTAINED ON A DEDICATED WIKI SITE:</strong> [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 <tt>cpdo_stmt</tt> 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 <tt>cpdo_driver</tt> 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.

Z 216f19ac005373ebbb5813ca986d9c9d