I’d like to kill a thread from another thread and I’d like to do when it is running, so it won’t be anything like change the loop variable to something. What would be the most appropriate way to do it?
To be more clear, I am using cURL and after some point i don’t want curl to perform downloading. curl API does not provide anything like that. So I have to cancel the thread.
Killing a thread is rarely a good idea because it can very easily lead to memory/resource leaks. A killed thread only cleans up it’s stack and the memory used by the thread itself, nothing allocated via new/malloc etc.
However, if you really want to kill the thread, with pthreads the correct way to do it is to call
pthread_cancel.Also: look here:
Cancelling a thread using pthread_cancel : good practice or bad