Ideas about implementing this multithreaded situation...

From: Ritesh (Ritesh_at_discussions.microsoft.com)
Date: 02/27/05


Date: Sun, 27 Feb 2005 00:17:03 -0800

Hello,

We are developing a GUI for MySQL RDBMS.

Users can write a query and execute it. We execute the query using MySQL C
API mysql_query() and return the result.

Every instance of a MySQL connection is denoted by MYSQL structure.

Now, mysql_query() is a blocking function, so until and unless it executes
and gets all the result, it will stop there. Therefore, if a query resturs a
cartesian product or takes a lot time there is no way to stop the query. The
only way to do is to create another connection to the same server and kill
the current connection.

To provide the user a good interface to stop a query, we execute the query
in a different thread and if a user clicks on the stop button, this is what I
plan to do:

1.) Create another connection to the MySQL Server
2.) If successful then terminate the thread.

But looking in the remarks of TerminateThread(...) function in MSDN, i get:

- If the target thread is allocating memory from the heap, the heap lock
will not be released.

And I am actually doing it so I believe TerminateThread (...) is not a
*good* option.

What should I do handle such situation? I want to get out of the thread as
soon as I have successfuly created another connection?

Forgot to mention - if I kill a MYSQL connection then an existing running
query in that connection returns a generic error so I dont know whether its a
normal error or error due to killing of connection.

PS: I am doing all the GUI updation like showing the result etc, in the
child thread only.

Hope I have been clear!

Regards,
Ritesh


Quantcast