Miro Bucko
Miro Bucko

Reputation: 1133

Joining and terminating a windows thread

I am trying to create a thread using windows threads as following:

HANDLE hUSBPollThread = CreateThread(
            NULL,
            NULL,
            USBCan::CreateUSBPollLoop,
            (LPVOID) this,
            0,
            &outThreadID);  

However I could not find any functions to Join or Terminate the thread from outside of the thread. Could anyone point me to the right direction?

Upvotes: 1

Views: 2126

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

If you terminate the thread externally, how can you be sure that no resources are leaked, no synchronization objects are left locked? Yes you can kill thread with TerminateThread but you should not be doing it.

What you do instead is: you signal an internal event that you want to terminate thread operation, and thread proc will eventually notice this request and return/exit closing thread activity.

Upvotes: 2

Related Questions