From owner-freebsd-threads@FreeBSD.ORG Thu Feb 16 21:33:06 2012 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7B79A1065670 for ; Thu, 16 Feb 2012 21:33:06 +0000 (UTC) (envelope-from JAxboe@fusionio.com) Received: from mx1.fusionio.com (mx1.fusionio.com [66.114.96.30]) by mx1.freebsd.org (Postfix) with ESMTP id 4F7748FC15 for ; Thu, 16 Feb 2012 21:33:06 +0000 (UTC) X-ASG-Debug-ID: 1329426816-03d6a50ee0138200001-TYnE9X Received: from mail1.int.fusionio.com (mail1.int.fusionio.com [10.101.1.21]) by mx1.fusionio.com with ESMTP id 6Wqqh7uHIwmH680t; Thu, 16 Feb 2012 14:13:36 -0700 (MST) X-Barracuda-Envelope-From: JAxboe@fusionio.com Received: from [192.168.0.212] (188.20.58.220) by mail.fusionio.com (10.101.1.19) with Microsoft SMTP Server (TLS) id 8.3.83.0; Thu, 16 Feb 2012 14:13:35 -0700 Message-ID: <4F3D717C.9040309@fusionio.com> Date: Thu, 16 Feb 2012 22:13:32 +0100 From: Jens Axboe MIME-Version: 1.0 To: Julian Elischer References: <4F3C2671.3090808__7697.00510795719$1329343207$gmane$org@freebsd.org> <4F3D3E2D.9090100@FreeBSD.org> <4F3D6FDD.9050808@freebsd.org> X-ASG-Orig-Subj: Re: pthread_cond_timedwait() broken in 9-stable? (from JAN 10) In-Reply-To: <4F3D6FDD.9050808@freebsd.org> X-Enigmail-Version: 1.3.5 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Barracuda-Connect: mail1.int.fusionio.com[10.101.1.21] X-Barracuda-Start-Time: 1329426816 X-Barracuda-URL: http://10.101.1.180:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.88735 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Cc: Kabaev , "threads@freebsd.org" , FreeBSD Stable , Andriy Gapon , Alexander Subject: Re: pthread_cond_timedwait() broken in 9-stable? (from JAN 10) X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Feb 2012 21:33:06 -0000 On 2012-02-16 22:06, Julian Elischer wrote: > On 2/16/12 9:34 AM, Andriy Gapon wrote: >> on 15/02/2012 23:41 Julian Elischer said the following: >>> The program fio (an IO test in ports) uses pthreads >>> >>> the following code (from fio-2.0.3, but its in earlier code too) >>> has suddenly started misbehaving. >>> >>> clock_gettime(CLOCK_REALTIME,&t); >>> t.tv_sec += seconds + 10; >>> >>> pthread_mutex_lock(&mutex->lock); >>> >>> while (!mutex->value&& !ret) { >>> mutex->waiters++; >>> ret = pthread_cond_timedwait(&mutex->cond,&mutex->lock,&t); >>> mutex->waiters--; >>> } >>> >>> if (!ret) { >>> mutex->value--; >>> pthread_mutex_unlock(&mutex->lock); >>> } >>> >>> >>> It turns out that 'ret' sometimes comes back instantly (on my machine) with a >>> value of 60 (ETIMEDOUT) >>> despite the fact that we set the timeout 10 seconds into the future. >>> >>> Has anyone else seen anything like this? >>> (and yes the condition variable attribute have been set to use the REALTIME clock). >> But why? >> >> Just a hypothesis that maybe there is some issue with time keeping on that system. >> How would that code work out for you with MONOTONIC? > > Jens Axboe, (CC'd) tried both CLOCK_REALTIME and CLOCK_MONOTONIC, and > they both had the same problem.. > i.e. random early returns with ETIMEDOUT. Yep indeed, using either MONOTONIC or REALTIME (and having set both with pthread_condattr_setclock()), no change in behaviour. -- Jens Axboe