B
Bill
Hi all,
I've got some code which monitors a file by way of the kqueue/kevent
mechanism but I'm having trouble getting it to shut down cleanly.
My thread dedicated to the kqueue is basically a while-loop which
blocks on the kevent() call until an event is posted, at which point it
rattles through and does what it's supposed to. So far so good.
while(watcherRunning==true){
n = kevent(kq, NULL, 0, out_list, 255, NULL);
//got an event, do something with it.
}
The problem comes when I want to stop monitoring the file. As far as I
can see, the only way to get it to stop is to set "watcherRunning" to
false (from within a separate thread) and then actually make a change
to the file in order to trigger a kevent and unblock the thread!
Surely there must be a nicer way to do it?
Is there any way to trigger/post a kevent programmatically?
I don't really want to set a timeout on the event blocking as that
isn't really practical and it also turns it into a poll thereby
defeating the purpose of using a kqueue in the first place!
I'm tearing my hair out, can anyone help please?
Thanks a million for any help.
W
I've got some code which monitors a file by way of the kqueue/kevent
mechanism but I'm having trouble getting it to shut down cleanly.
My thread dedicated to the kqueue is basically a while-loop which
blocks on the kevent() call until an event is posted, at which point it
rattles through and does what it's supposed to. So far so good.
while(watcherRunning==true){
n = kevent(kq, NULL, 0, out_list, 255, NULL);
//got an event, do something with it.
}
The problem comes when I want to stop monitoring the file. As far as I
can see, the only way to get it to stop is to set "watcherRunning" to
false (from within a separate thread) and then actually make a change
to the file in order to trigger a kevent and unblock the thread!
Surely there must be a nicer way to do it?
Is there any way to trigger/post a kevent programmatically?
I don't really want to set a timeout on the event blocking as that
isn't really practical and it also turns it into a poll thereby
defeating the purpose of using a kqueue in the first place!
I'm tearing my hair out, can anyone help please?
Thanks a million for any help.
W