J
Joel Yliluoma
Obviously you mean
A tmp;
std::swap(tmp.a, tmp.c);
?
Yes, sorry.
Obviously you mean
A tmp;
std::swap(tmp.a, tmp.c);
?
The fact that a Z80 actually had to read or read/modify/write an
entire 8-byte byte to test, set, or clear a single bit was completely
immaterial from an architectural point of view, that's a hardware
implementation detail.
Would you claim that a Pentium was not "really" byte addressable,
because it will read a minimum of 64 bits from memory to change the
value of just one of them?
Given:
char ca [8] = { 0 };
++ca[4];
...the processor hardware will execute at least two 64-bit bus
cycles, reading the entire contents of the array if it is
suitably aligned to get at ca[4]. If it winds up in the
cache, it will eventually write all 64 bits back to memory,
even though only one 8-bit octet is changed.
set 0,(hl)
...on a Z80 was a single, and atomic, instruction, regardless
of what the hardware did to make it happen.
James said: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[4]. Thread 2 (on processor 2, with cache 2) reads the array,
and modifies ca[3]. The last one to write overwrites the
other's modification.
James said: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[4]. Thread 2 (on processor 2, with cache 2) reads the array,
and modifies ca[3]. The last one to write overwrites the
other's modification.
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.)
James said: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?
Yes, I would recommend std::bitset, but that would not answer the
question.
No. I mean that when two processors, each one with their own
L1 cache, have the same memory block cached, when one of the
processors change the memory location, the other processor
(well, more specifically its cache logic) detects this
change and invalidates the data in its own cache.
SMP-multithreading with multiple processors obviously couldn't
function properly without this kind of logic.
IIRC modifying a shared memory location is an atomic operation even in
a multi-processor system (well, at least in the intel architecture),
so two modifications of the same memory location are
guaranteed never to happen exactly at the same time. (Don't
shoot me if I'm remembering wrong here, but I'm pretty certain
it was this way.)
Because a byte is the smallest addressible unit in the language.
Consider:
bool foo;
bool *pfoo = &foo;
If a bool consists of a single bit, now what?
Of course, you can make your own bit sets very easily if you like (to
conserve space).
No. I mean that when two processors, each one with their own L1 cache,
have the same memory block cached, when one of the processors change the
memory location, the other processor (well, more specifically its cache
logic) detects this change and invalidates the data in its own cache.
SMP-multithreading with multiple processors obviously couldn't
function properly without this kind of logic.
IIRC modifying a shared memory location is an atomic operation even in
a multi-processor system (well, at least in the intel architecture), so
two modifications of the same memory location are guaranteed never to
happen exactly at the same time. (Don't shoot me if I'm remembering
wrong here, but I'm pretty certain it was this way.)
what if two processors almost simultaniously change contents of their
cache locations that represent the same memmory location?
If I am not wrong this is a semaphore handled via hardware or master
processor`s software . I guess cached portion of memory needs be
locked(write-protected('const'ed) in better words) when one processor
uses(read/writes) its cache so that the second processor is
banned(interupted) from writing to its cache in case of referencing
cache location representing an address in the portion of memmory
cached by the first processor.
just my guess,
FM.- Hide quoted text -
- Show quoted text -
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.