Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Oct 2003 17:40:18 -0700
From:      Tim Kientzle <kientzle@acm.org>
To:        Bruce M Simpson <bms@spc.org>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Dynamic reads without locking.
Message-ID:  <3F875172.5010309@acm.org>
In-Reply-To: <20031008101251.GG6524@saboteur.dek.spc.org>
References:  <20031008083059.GA520@garage.freebsd.pl> <20031008114506.I63940@beagle.fokus.fraunhofer.de> <20031008101251.GG6524@saboteur.dek.spc.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Bruce M Simpson wrote:
> On Wed, Oct 08, 2003 at 11:51:06AM +0200, Harti Brandt wrote:
>>You need to lock when reading if you insist on consistent data. Even a
>>simple read may be non-atomic (this should be the case for 64bit
>>operations on all our platforms).
> 
> Or keep a generation count to detect pre-emption (the devstat code does
> this, amongst other things), and try again if you lost the race.

Are you sure that code is right?  I'm not at all convinced that the
compiler is forbidden from simply optimizing away most of your
generation count code.  (Just because gcc doesn't do so today
doesn't mean that icc or gcc 4 won't.)

I'd be a lot more convinced by code that allocated a non-shared buffer,
locked the mutex, copied the data into the buffer, unlocked,
pushed the data out from the buffer, then released the buffer.

Many attempts to avoid locking are foiled by compiler optimizations.

Tim Kientzle



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3F875172.5010309>