Re: [PHP4BETA] Databases and multithreading
| From: | Sascha Schumann | Date: | Fri, 08 Oct 1999 20:32:51 +0000 |
| Subject: | Re: [PHP4BETA] Databases and multithreading | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-5419@lists.php.net to get a copy of this message | ||
On Fri, Oct 08, 1999 at 07:47:43PM +0000, Andreas Karajannis wrote:
> To make the database modules thread safe, I think there are changes
> with persistent connection handling required:
>
> Currently only one identical connection per process is allowed -
> attempting to pconnect with the same parameters will return the
> previously
> established connection out of the plist. If I got things right, we end
> up
> with several threads using the same single connection.
> Besides the fact, that this is not what we want (a single db connection)
> there will be multiple threads trying to execute quasi simultaneous
> queries
> on the same connection...
>
> So we need some kind of mutexing for pconnetions: The connection handle
> returned from pconnect() mustn't be available for other threads until
> explicitly released (via close()) or implicitly released on request
> shutdown.
>
> Non persistent connections should be ok, since they are kept in a per
> thread
> resource list.
>
> Any opinions on this from more "threaded" people?
Thies and I discussed this earlier. We would practically need
a third resource list, which would make resources available
across threads.
--
Regards,
Sascha Schumann
Consultant
The scope of a resource is a standard UNIX process. Thus, if using ZTS, resources can be shared across multiple threads. A resource lives until the process terminates. On termination, all resources are destructed in random order. The destructor, if available, is called with the original key and the data the constructor returned. res_type register_resource_type(char *name, void *(*ctor)(char *key), void (*dtor)(char *key, void *data), int maxref); Registers a resource type, and saves the data for later usage. ctor constructor dtor destructor maxref maximum reference count long register_resource(res_type type, char *key); Checks whether a resource with the specific `key' exists. If such a resource is found and the maxref value has not been reached yet, the reference count is increased, and the id of the resource is returned. If such a resource is not found, it calls the constructor of the resource type with `key' as parameter. If this function returns NULL, the constructor failed. Otherwise, a new resource is created, with the return value of the constructor as data; the reference count is set to 1. The id of the new resource is returned. If no resource is found, and the creation of a new one failed, this function returns -1. void release_resource(long id); Decreases the reference count of resource `id.' void *fetch_resource(long id, res_type *type); Returns the data associated with `id' and stores the resource type in `type,' if the resource exists, or returns NULL, if the resource does not exist.
The scope of a resource is a standard UNIX process. Thus, if using ZTS, resources can be shared across multiple threads. A resource lives until the process terminates. On termination, all resources are destructed in random order. The destructor, if available, is called with the original key and the data the constructor returned. res_type register_resource_type(char *name, void *(*ctor)(char *key), void (*dtor)(char *key, void *data), int maxref); Registers a resource type, and saves the data for later usage. ctor constructor dtor destructor maxref maximum reference count long register_resource(res_type type, char *key); Checks whether a resource with the specific `key' exists. If such a resource is found and the maxref value has not been reached yet, the reference count is increased, and the id of the resource is returned. If such a resource is not found, it calls the constructor of the resource type with `key' as parameter. If this function returns NULL, the constructor failed. Otherwise, a new resource is created, with the return value of the constructor as data; the reference count is set to 1. The id of the new resource is returned. If no resource is found, and the creation of a new one failed, this function returns -1. void release_resource(long id); Decreases the reference count of resource `id.' void *fetch_resource(long id, res_type *type); Returns the data associated with `id' and stores the resource type in `type,' if the resource exists, or returns NULL, if the resource does not exist.