closing a kqueue

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
 
B

Ben Pfaff

Bill said:
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.

You'd be better off asking about this in a newsgroup dedicated to
whatever OS kqueue/kevent are part of.
 
C

CBFalconer

Bill said:
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.

This has nothing to do with the ISO standard C language, and thus
is off-topic here. I suspect it may have something to do with
Linux/Unix and/or KDE. You need to find a newsgroup that deals
with those systems. Possibly comp.unix.programmer. Don't break
into it without first lurking and finding out if your problem is
topical. Meanwhile, read the following links.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net> (C-info)
 
M

mark_bluemel

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. [Snip]
Is there any way to trigger/post a kevent programmatically?

<Off-topic>
I know nothing of kqueues apart from a rapid glance at the online
documentation.
Could you (e.g.) use a pipe and write to it from the other thread?

It's possible, but not hugely likely, that someone reading a forum on
general C Language programming will have intimate knowledge of a
feature which as far as I can see is specific to recent BSD-derived
operating systems.

Somewhere like http://www.freebsd.org/support.html may be a more useful
source of information. Perhaps look at the mailing lists at
http://www.freebsd.org/community/mailinglists.html?
</Off-topic>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top