Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Sep 2003 11:45:37 -0400 (EDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        smp@freebsd.org
Subject:   RE: atomicity of unlocked reads
Message-ID:  <XFMail.20030917114537.jhb@FreeBSD.org>
In-Reply-To: <20030917122543.O8168@gamplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help

On 17-Sep-2003 Bruce Evans wrote:
> What guarantees, if any, are there that an unlocked read provides a
> valid value (either the current value or a previous value)?  Obviously
> there are no guarantees if the size of the object being read is different
> from the natural memory access size.
> 
> I'm mainly interested in atomic reads of pointers in circular buffers.
> The read pointer is only written to by one thread and is locked by
> lock R.  The write pointer is only written to by another thread and
> is locked by a different lock W.  Each thread needs to read but not
> write the other thread's pointer but doesn't care if it sees a stale
> value (it will see an up to date value later), but does care if it
> sees a garbage value.  It would be nice if each thread doesn't have
> to use the other thread's lock, especially when one of the threads is
> actually a fast interrupt handler so it can't use the other thread's
> lock unless it is a spinlock but wants to be a sleep lock.
> 
> Sometimes even a garbage value from reading an object non-atomically
> might not matter.  E.g., in sigpending() there seems to be no point
> in locking the read, since a snapshot that is inconsistent due to not
> locking during the read is little different from a snapshot that is
> inconsistent due to the object changing after it is read.

I think you can assume that the read will be atomic.  I don't think FreeBSD
would work very well on a machine where aligned pointer reads/writes weren't
atomic.

-- 

John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20030917114537.jhb>