Date: Wed, 17 Sep 2003 12:46:41 +1000 (EST) From: Bruce Evans <bde@zeta.org.au> To: smp@freebsd.org Subject: atomicity of unlocked reads Message-ID: <20030917122543.O8168@gamplex.bde.org>
next in thread | raw e-mail | index | archive | help
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. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030917122543.O8168>