[MUD-Dev] Two threads forced to one CPU? (was: Collecting ideas for a MUD server...)

cg at ami-cg.GraySage.Edmonton.AB.CA cg at ami-cg.GraySage.Edmonton.AB.CA
Tue Dec 28 09:39:06 New Zealand Daylight Time 1999

[Hans-Henrik Staerfeldt:]

> Yes, or keep assuming the worst possible. Assume that the thread can be 
> interrupted, after you have written down 16 of 32 bit of any long word 
> in the memory, making the 32-bit value non-valid, which is why you need
> thread-safe system calls :-) I actually had this error, though on older 
> hardware.

As far as I know, that shouldn't be a problem on a 32 bit CPU. The
instructions, if done properly aligned, should be single, atomic instructions.

The rule is likely something like: do not assume atomicity of operations
for any operations which operate on values larger than the word-size of
the machine, or on *any* struct/class values. So, on a 16 bit MC68000,
watch out for 32 bit values - they may not be atomic on memory accesses.
On a 32 bit IA32 (e.g. Pentium) machine, watch out for operations on 64
bit values - they may not be atomic with respect to memory. On a 64 bit
machine, e.g. an Alpha, watch out for 128 bit operations, etc.

There are of course exceptions. I believe newer Pentia have some explicit
64 bit special instructions, and since their off-chip bus width is
sometimes > 32 bits, these can work atomically. Unless you know the
specifics, however, and want your software to not be readily portable to
other CPU variants (even other I32's!), don't assume anything.

Don't design inefficiency in - it'll happen in the implementation.

Chris Gray     cg at ami-cg.GraySage.Edmonton.AB.CA

MUD-Dev maillist  -  MUD-Dev at kanga.nu

More information about the MUD-Dev mailing list