Say I have a thread that's something like this:
void my_thread(char *device_name) {
int fd = open(device_name, O_RDONLY);
struct input_event ev;
while(1) {
read(fd, &ev, sizeof(struct input_event));
/* do something */
}
}
How do I stop such a thread? One way is using pthread_cancel
, but I'd rather do it more gracefully. Something like pthread_kill
perhaps? In such case, however, would the read method unblock (as I presume it should) and how would the thread handle the signal? Or is it the process that should handle it?
I'd be very grateful for an advice!