Hello all,

I have a question about threading with MySQL I hope you can help me with.

Here's the situation:

I am developing a driver to allow MySQL to be used as a database for a
server.  The server operates on Windows and many *nix variants.  The server
CAN run in single and multi-threaded modes.

The driver must be developed using the servers "driver api".  Using this api
there is no way to be informed of a thread starting or ending...  So I can't
put my_thread_init() at the start of a new thread, and I can't put
my_thread_end() at the ending of a thread.  Also there is NO guarantee that
the thread that called my_init() will be the only one attempting to perform
MySQL operations.

So..  What is the best way to use MySQL in this scenario?

Options that I have thought of:

1) Only allow the MySQL driver to be used when the server is operating in
single threaded mode.  This would eliminate all threading issues.  But, I
really don't want to have to impose this limitation.

2) Call my_thread_init() at the beginning of a threads operation within the
driver, and my_thread_end() at the end.  What kind of problems would this
cause if the thread entering the driver already had my_init() called on it,
and thus already has the vars created by my_thread_init()?  What happens
once everythread has been through the driver once and my_thread_end() has
been called on every thread?  I want to create and keep open a pool of
connections when the driver starts up.  Will it be possible for the pool
connections to be kept open / alive if every thread has had my_thread_end()
called on it?

here's the basic sequence of the driver:

Server starts up
Driver is started
call my_init()
multiple connections to MySQL created
Additional threads start

a Thread enters driver to perform work  - no control over which threads.
do???  my_thread_init()   perform query..   my_thread_end()
a thread leaves driver

Server signaled to shut down
Driver is signaled to shut down
Connections to MySQL closed
call my_??? to cleanup and end use of MySQL.
Driver shutdown complete
Server shutdown complete

I hope this is clear enough for everyone to understand...
Thanks for your help in advance
Rob



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to