User: Password:
|
|
Subscribe / Log in / New account

Mean value

Mean value

Posted Feb 3, 2006 3:28 UTC (Fri) by obobo (guest, #684)
In reply to: Mean value by madscientist
Parent article: The search for fast, scalable counters

In general, you can run into problems where the counter is being incremented as it is being read. Say you're using a (mythical) 8-bit architecture, and the 16-bit counter value is being incremented from 0x00ff to 0x0100. The intermediate state, as the counter is being updated, will be 0x0000 (or perhaps 0x01ff) because only 8 bits are being written at a time. Much worse than the off-by-one situation that I think you were imagining. And worse still if it is a 64 bit counter on a 32 bit system...

Caveat- I don't know anything the specific types mentioned in the article (local_t in particular) so this particular problem might not be an issue there depending on how the atomicity of it works.


(Log in to post comments)

Mean value

Posted Feb 3, 2006 10:39 UTC (Fri) by man_ls (guest, #15091) [Link]

So, just stick to the size native to the architecture. On 32-bit machines, never use more than 32 bits for the intermediate values; if you happen to be on a Z80 (not so mythical 8-bit architecture) use a max value of 255 for them.

Incrementing a 32-bit register on a 32-bit architecture is an atomic operation even on multi-processor systems, right?


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds