Re: Why bool take 1 byte?
On Nov 5, 4:44 am, Juha Nieminen <nos...@thanks.invalid> wrote:
James Kanze wrote:
Are you sure of this? If so, it makes multithreaded code pretty
much impossible, at least with the usual definitions. Thread 1
(on processor 1, with cache 1) reads the array, and modifies
ca. Thread 2 (on processor 2, with cache 2) reads the array,
and modifies ca. The last one to write overwrites the
Processors (well, more accurately the cache management logic) are
smarter than that. They can detect if a portion of memory cached in two
different processor caches has been modified by the other processor.
(This will of course cause clock cycle penalties while the caches are
synchronized, but it will not cause a malfunction.)
You mean when it goes to write the memory back from cache? That
the processor detects that its image is not consistent with that
in main memory?
I've not looked at that level (only at the formal guarantees
provided by the architecture), but somehow, I'm sceptical. What
would the processor do if it detects that the byte had been
modified both in its own cache, and in the main memory?
(At the level of formal guarantees, modifying ca on one
processor, and ca on the other, is guaranteed to work without
any external synchronization. Although I'm aware of at least
one very old processor where that wasn't the case.)
James Kanze (GABI Software) email:email@example.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34