Date: Tue, 10 Apr 2012 15:25:40 +0100 From: Ben Short <ben@benshort.co.uk> To: freebsd-questions@freebsd.org Subject: Using kqueue with 2 threads Message-ID: <CAOiKr=t3V=MWCc6Z_%2BskZYkS-jrXwXUiOkuOk7N_sBCaKWMZxQ@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Hi, I'm trying to use a kqueue to listen for VNODE events on a worker thread. I want new events to be registered with the kqueue by a separate thread. I have been referring to this example [URL=" http://doc.geoffgarside.co.uk/kqueue/file.html"] http://doc.geoffgarside.co.uk/kqueue/file.html[/URL] Here are the relevant parts of code as it is at the moment. In my worker thread: [CODE]std::cerr << "Started worker" << std::endl; struct kevent ke; int i; while ( !mStopRequested ) { memset(&ke, 0x00, sizeof(kevent)); i = kevent(kq, NULL, 0, &ke, 1, NULL); if ( i == -1 ) { std::cerr << "kqueue produced error: " << strerror(i) << std::endl; continue; // todo is this the best thing todo? } std::cerr << "Beep: " << i << std::endl; } std::cerr << "Shutting down worker" << std::endl;[/CODE] Other thread [CODE]int fd = open(fileName.c_str(), O_RDONLY); if ( fd == -1 ) { std::cerr << "Failed to open file: " << fileName << " Error: " << strerror(errno) << std::endl; // todo throw exception } struct kevent ke; EV_SET(&ke, fd, EVFILT_VNODE, EV_ADD, NOTE_DELETE | NOTE_RENAME | NOTE_EXTEND, 0, NULL); if (kevent(kq, &ke, 1, NULL, 0, NULL) == -1) { std::cerr << "kevent produced error: " << strerror(errno) << std::endl; }[/CODE] When I run my code the kevent call in the worker code doesn't block at all. Any ideas what I'm missing? or if what I want to do is even possible? Ben
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOiKr=t3V=MWCc6Z_%2BskZYkS-jrXwXUiOkuOk7N_sBCaKWMZxQ>