Ending a Thread

DosKillThread ends a thread in the current process. DosKillThread enables a thread in a process to end any other thread in the process.

DosKillThread is used to force a thread within the current process to end without causing the entire process to be ended.

    #define INCL_DOSPROCESS       /* Process and thread values */
    #include <os2.h>

    TID tidThread;    /* ThreadID of the thread to be ended */

    DosCreateThread(&tidThread,
                    ThreadFunction,
                    0,
                    0,
                    4096);
    .
    .
    .
    DosKillThread(tidThread);

DosKillThread returns to the requestor without waiting for the target thread to complete its termination processing.

It is an invalid operation to use DosKillThread to kill the current thread.

Terminating thread 1 will cause the entire process to end similar to executing DosExit on thread 1. DosKillThread will not end a thread that is suspended. Instead the suspended thread will be ended when it resumes execution. For this reason, you should not kill the main thread of an application if there are any secondary threads that are suspended.

If the target thread is executing 16-bit code or was created by a 16-bit requester, ERROR_BUSY is returned.


[Back: Ending the Current Thread]
[Next: Using Sessions]