Subject: Re: ingres and atomicity
To: None <tech-userlevel@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 06/14/2005 21:07:43
>> It is a highly platform (well, CPU, mostly)-specific question.
> I know, but I'm a userland program, so I need a kernel service.

No...you may need an architecture-dependent service, but that doesn't
necessarily mean a kernel service.  A routine form an OS library such
as libc might do as well.

> David Laight said "Code will assume that a write of a 32bit (aligned)
> quantity is atomic", but that the functions I quoted refer to 64-bit
> values.

There is a good deal of research among OS theorists on implementing
locking without hardware-assisted locking primitives.  I once did a
little reading and thought about it and convinced myself that with some
fairly weak assumptions (basically, that you have a data type holding
at least one bit of information which can be read and written such that
reads and writes appear to occur atomically in some order), it was
possible to construct locking among semi-arbitrary numbers of
cooperating accessors.  ("Semi-arbitrary" because the methods I used
require assuming a compile-time, or possibly even code-write-time,
limit on the number of concurrent accessors.)

If you have data large than one bit with that property - such as the
32-bit values you quote David Laight as writing of - then the problem
gets correspondingly easier.

However, that's a theoretical result.  Depending on various factors
such as how large the critical sections in question are, it may or may
not be more efficient to do such things than to punt to a syscall.

If you want I can go dig out the references I used and reconstruct my
conclusions.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B