看板 FB_smp 關於我們 聯絡資訊
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/ _______________________________________________ freebsd-smp@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-smp To unsubscribe, send any mail to "freebsd-smp-unsubscribe@freebsd.org"