On 06/13/2011 11:23 PM, Juan Pablo L wrote:
attached is source for database pool module,

Besides from the locking issues outlined here, you are doing it wrong.
You can run a postgres database connection completely nonblocking, without threads. While it is not easy to get things right the first time - better read the docs twice, it is much easier to use the nonblocking interface than dealing with threads & mutexes.

If the database-con is busy, queue the request, if the database-con is available run a request from the queue, if the database-con wants to read, EV_READ, if the database-con wants to write, EV_WRITE to the appropriate callback. Give each request a callback to report the result, call the callback once the query is done and block issuing new requests on the database-con during while the callback is running.

As there is very little computation required on the client side of a database connection you do not need threads anyway, and not having mutexes is likely to make the code easier and more scalable therefore.


_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to