How can I go about emulating the pthread_kill() function with C++ threads? I asked a question about this earlier but there was no response to it. Will the thread::native_handle() function help here?
To execute the c file, we have to use the -pthread or -lpthread in the command line while compiling the file. Syntax: int pthread_create(pthread_t * thread, const pthread_attr_t * attr, void * (*start_routine)(void *), void *arg);
The pthread_kill() function sends the signal sig to thread, a thread in the same process as the caller. The signal is asynchronously directed to thread. If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a thread ID.
You could call std::terminate() from any thread and the thread you're referring to will forcefully end. You could arrange for ~thread() to be executed on the object of the target thread, without a intervening join() nor detach() on that object.
thread::native_handleReturns the implementation defined underlying thread handle.
So the answer to this question is to rely on platform dependent features and use std::thread::native_handle
with pthread_kill()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With