cpdo  Update of "CpdoAndThreads"

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 37c15014150cdc8a2b2947b446d225e55715ef75
Page Name:CpdoAndThreads
Date: 2011-05-17 18:39:27
Original User: stephan
Parent: f01ebcd38a2cfcfad6ea2ede79f412ceb919c05c
Content

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.