How can a thread be terminated unconditionally?

I am trying to creating a means of terminating long running DB2 queries on an AS400.

In an attempt to do this I have created a multithread program that runs DB2 queries using two

threads. The first threads creates a semaphore, starts a thread, then waits with a timeout on the

semaphore. The thread function then runs an SQL query the posts a semaphore and

terminates itself.

The problem occurs when the queries takes a long time to run. The parent thread, now unblocked

because of a timeout, tries to terminate the thread using the AS400 Cancel_Thread function.

According to AS400 documentation this function can only terminate threads when the thread

status is cancelable and when the thread function calls Check_Cancel.

When the thread is running an SQL query it cannot call Check_Cancel and cannot be terminated.

How can the SQL be terminated? Without terminating the program? Will terminating the program kill the thread?