From owner-freebsd-current@FreeBSD.ORG Fri Oct 14 10:30:04 2005 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7B40616A41F for ; Fri, 14 Oct 2005 10:30:04 +0000 (GMT) (envelope-from PeterJeremy@optushome.com.au) Received: from mail14.syd.optusnet.com.au (mail14.syd.optusnet.com.au [211.29.132.195]) by mx1.FreeBSD.org (Postfix) with ESMTP id BF71643D45 for ; Fri, 14 Oct 2005 10:30:03 +0000 (GMT) (envelope-from PeterJeremy@optushome.com.au) Received: from cirb503493.alcatel.com.au (c220-239-19-236.belrs4.nsw.optusnet.com.au [220.239.19.236]) by mail14.syd.optusnet.com.au (8.12.11/8.12.11) with ESMTP id j9EAU19E028938 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Fri, 14 Oct 2005 20:30:02 +1000 Received: from cirb503493.alcatel.com.au (localhost.alcatel.com.au [127.0.0.1]) by cirb503493.alcatel.com.au (8.12.10/8.12.10) with ESMTP id j9EAU0Hh009592; Fri, 14 Oct 2005 20:30:01 +1000 (EST) (envelope-from pjeremy@cirb503493.alcatel.com.au) Received: (from pjeremy@localhost) by cirb503493.alcatel.com.au (8.12.10/8.12.9/Submit) id j9EAU0Mk009588; Fri, 14 Oct 2005 20:30:00 +1000 (EST) (envelope-from pjeremy) Date: Fri, 14 Oct 2005 20:30:00 +1000 From: Peter Jeremy To: Brian Candler Message-ID: <20051014102959.GB7346@cirb503493.alcatel.com.au> References: <434E46C0.7060903@centtech.com> <200510131412.23525.max@love2party.net> <20051013181026.GB27418@odin.ac.hmc.edu> <20051014091004.GC18513@uk.tiscali.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051014091004.GC18513@uk.tiscali.com> User-Agent: Mutt/1.4.2.1i Cc: freebsd-current@freebsd.org Subject: Re: ufsstat - testers / feedback wanted! X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Oct 2005 10:30:04 -0000 On Fri, 2005-Oct-14 10:10:04 +0100, Brian Candler wrote: >I'd be grateful if you could clarify that point for me. Are you saying that >if I write > > long long foo; > ... > foo++; > >then the C compiler generates code for 'foo++' which is not thread-safe? >(And therefore I would have to protect it with a mutex or critical section) foo++ is not normally thread-safe even if foo is an int or pointer. Typical iA32 code looks like: addl $1,foo This is only thread-safe in a UP environment. Typical RISC code looks like: load foo,%reg add $1,%reg store %reg,foo This is not thread-safe. Note that the compiler may keep foo in a register for an extended period unless you convince the compiler not to. Especially on RISC processors, the compiler will normally spread the load/add/store to try and avoid pipeline stalls. If you share foo between two threads, you need to use atomic operations (see ), mutexes or critical sections on all updates. Note that you can do atomic 64-bit operations on iA32 (except 80386 and 80486) using a locked cmpxchg8b in a loop. -- Peter Jeremy