From owner-freebsd-questions@FreeBSD.ORG Tue Apr 10 14:32:59 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F057D1065679 for ; Tue, 10 Apr 2012 14:32:59 +0000 (UTC) (envelope-from ben@benshort.co.uk) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 71A428FC15 for ; Tue, 10 Apr 2012 14:32:59 +0000 (UTC) Received: by lagv3 with SMTP id v3so5912399lag.13 for ; Tue, 10 Apr 2012 07:32:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=YV7jGlVnH80iZ8EswaFcrwW2xpqwgK1f5qBskBMqGOA=; b=knZiVjWlVZGzSrxnBYnFSrwXjT1uZqcd/WurttlFZmLE0lL2JJRiJK+3XbMAmIqEPK ICVybccq9WupnU6bSo+9xXjpXf5uX/Wm7zMhZgZkNuoACsAzy3c0tLSZkHfOi3x9fvJn mWeauWxH+tGiX0qr0Ckz+WlHC6qGr24che7UiJ6WunKNErxhZWD9a1eSSm+gFpUbxWFf UyZd18ZxV995+vsuWm+JCUdl4Zp9vCRZCWCl1Bf26wwo5daXJk/uc307qFiRrgbD1g3l Sz9/mWWgHijzlsskwCojMGmPZfBC0xtkrp/bvhsdGA25alEz/e6cEugP8c1LT89Sz1ig KBDw== MIME-Version: 1.0 Received: by 10.112.83.105 with SMTP id p9mr1333019lby.43.1334067940702; Tue, 10 Apr 2012 07:25:40 -0700 (PDT) Received: by 10.112.110.131 with HTTP; Tue, 10 Apr 2012 07:25:40 -0700 (PDT) Date: Tue, 10 Apr 2012 15:25:40 +0100 Message-ID: From: Ben Short To: freebsd-questions@freebsd.org X-Gm-Message-State: ALoCoQngA7wSQYDdmj32EIMOgyRqCV/bXKOg9RbBBIq4HZjJarz95JOGp548IYoThwOxwkfkYUTR Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Using kqueue with 2 threads X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Apr 2012 14:33:00 -0000 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