Reputation: 189
I want to manually wake up (by another thread in the same process) a thread sleeping on poll() function waiting for any input data available. Looks like I found a possible solution by sending signals, but I don't have any experience with them really. On this page I found a signal called SIGPOLL with codes like POLL_IN, POLL_MSG, but when I call it, the whole process is killed. How to send this signal without killing the whole process ?
Upvotes: 0
Views: 427
Reputation: 189
I used pipe() to solve this problem.
void a(int invokefd){
...
write(invokefd, "c", 1);
...
}
void b(int invokefd){
vector<pollfd> readfds;
...
pollfd invfd;
invfd.fd = invokefd;
invfd.events = POLLIN;
invfd.revents = 0;
readfds.push_back(invfd);
...
poll(&readfds[0], readfds.size(), -1);
...
}
void main(){
...
int invokedfs[2];
pipe(invokefds);
thread aTh(a, invokefds[1]);
thread bTh(b, invokefds[0]);
...
}
Upvotes: 1