Discussion:
Simultaneous access to memory
(too old to reply)
Peter Olcott
2010-04-06 20:47:19 UTC
Permalink
What happens when two processes access memory at literally
the same time, with one reading and another writing, does
the read or the write get mangled? I know the whole
semaphore lock stuff, I want to know what happens when one
skips this step.
Sjouke Burry
2010-04-06 21:46:44 UTC
Permalink
Post by Peter Olcott
What happens when two processes access memory at literally
the same time, with one reading and another writing, does
the read or the write get mangled? I know the whole
semaphore lock stuff, I want to know what happens when one
skips this step.
Skip that step and you have a pile of junk instead of a computer.
Peter Olcott
2010-04-06 22:54:12 UTC
Permalink
Post by Sjouke Burry
Post by Peter Olcott
What happens when two processes access memory at
literally the same time, with one reading and another
writing, does the read or the write get mangled? I know
the whole semaphore lock stuff, I want to know what
happens when one skips this step.
Skip that step and you have a pile of junk instead of a
computer.
I am taking this informal message to mean:
On and given hardware platform, a simultaneous read
operation interferes with a write operation such that the
write operation is garbled.
Peter Olcott
2010-04-06 22:55:05 UTC
Permalink
Post by Sjouke Burry
Post by Peter Olcott
What happens when two processes access memory at
literally the same time, with one reading and another
writing, does the read or the write get mangled? I know
the whole semaphore lock stuff, I want to know what
happens when one skips this step.
Skip that step and you have a pile of junk instead of a
computer.
On ANY given hardware platform, a simultaneous read
operation interferes with a write operation such that the
write operation is garbled.
Paul
2010-04-06 23:27:13 UTC
Permalink
Post by Sjouke Burry
Post by Peter Olcott
What happens when two processes access memory at
literally the same time, with one reading and another
writing, does the read or the write get mangled? I know
the whole semaphore lock stuff, I want to know what
happens when one skips this step.
Skip that step and you have a pile of junk instead of a
computer.
On ANY given hardware platform, a simultaneous read
operation interferes with a write operation such that the
write operation is garbled.
The read or the write will not be mangled. Operations are
atomic enough, to complete, and all you have to worry
about from a programming perspective, is whether the
order they complete in matters or not.

If a read-modify-write instruction is involved, that is
atomic enough to complete, without being snipped in half.
The benefit of using an actual RMW type instruction on the
computer, is the processor takes care of it being atomic.
The processor won't allow an RMW to be split in half.

http://en.wikipedia.org/wiki/Read-modify-write

Paul
Peter Olcott
2010-04-06 23:54:00 UTC
Permalink
Post by Paul
Post by Sjouke Burry
Post by Peter Olcott
What happens when two processes access memory at
literally the same time, with one reading and another
writing, does the read or the write get mangled? I
know the whole semaphore lock stuff, I want to know
what happens when one skips this step.
Skip that step and you have a pile of junk instead of a
computer.
On ANY given hardware platform, a simultaneous read
operation interferes with a write operation such that
the write operation is garbled.
The read or the write will not be mangled. Operations are
atomic enough, to complete, and all you have to worry
about from a programming perspective, is whether the
order they complete in matters or not.
If a read-modify-write instruction is involved, that is
atomic enough to complete, without being snipped in half.
The benefit of using an actual RMW type instruction on the
computer, is the processor takes care of it being atomic.
The processor won't allow an RMW to be split in half.
http://en.wikipedia.org/wiki/Read-modify-write
Paul
Great now I have a fast way to trigger my preemptive
scheduling.
Will it work the way that you suggest on all modern
hardware?
Paul
2010-04-07 03:53:59 UTC
Permalink
Post by Peter Olcott
Post by Paul
Post by Sjouke Burry
Post by Peter Olcott
What happens when two processes access memory at
literally the same time, with one reading and another
writing, does the read or the write get mangled? I
know the whole semaphore lock stuff, I want to know
what happens when one skips this step.
Skip that step and you have a pile of junk instead of a
computer.
On ANY given hardware platform, a simultaneous read
operation interferes with a write operation such that
the write operation is garbled.
The read or the write will not be mangled. Operations are
atomic enough, to complete, and all you have to worry
about from a programming perspective, is whether the
order they complete in matters or not.
If a read-modify-write instruction is involved, that is
atomic enough to complete, without being snipped in half.
The benefit of using an actual RMW type instruction on the
computer, is the processor takes care of it being atomic.
The processor won't allow an RMW to be split in half.
http://en.wikipedia.org/wiki/Read-modify-write
Paul
Great now I have a fast way to trigger my preemptive
scheduling.
Will it work the way that you suggest on all modern
hardware?
I don't know when it was introduced.

Maybe your programming environment has a primitive, and it
takes care of the details ?

Paul
Peter Olcott
2010-04-07 14:13:42 UTC
Permalink
Post by Paul
Post by Peter Olcott
Post by Paul
If a read-modify-write instruction is involved, that is
atomic enough to complete, without being snipped in
half.
The benefit of using an actual RMW type instruction on
the
computer, is the processor takes care of it being
atomic.
The processor won't allow an RMW to be split in half.
http://en.wikipedia.org/wiki/Read-modify-write
Paul
Great now I have a fast way to trigger my preemptive
scheduling.
Will it work the way that you suggest on all modern
hardware?
I don't know when it was introduced.
Maybe your programming environment has a primitive, and it
takes care of the details ?
No, not at all. The reason that I asked this question is so
that I would know the limits of the degree that I could
enhance the behavior of the operating system.

As long as one process reading a memory location does not
ever mangle another process writing to this location, even
if the read may get mangled data when it occurs at the exact
same moment as the write, then I am good to go. It would be
even better if the read never gets mangled too. It looks
like you are saying that I can count on both of these
behaviors.
Post by Paul
Paul
Paul
2010-04-07 17:54:14 UTC
Permalink
Post by Peter Olcott
Post by Paul
Post by Peter Olcott
Post by Paul
If a read-modify-write instruction is involved, that is
atomic enough to complete, without being snipped in
half.
The benefit of using an actual RMW type instruction on
the
computer, is the processor takes care of it being
atomic.
The processor won't allow an RMW to be split in half.
http://en.wikipedia.org/wiki/Read-modify-write
Paul
Great now I have a fast way to trigger my preemptive
scheduling.
Will it work the way that you suggest on all modern
hardware?
I don't know when it was introduced.
Maybe your programming environment has a primitive, and it
takes care of the details ?
No, not at all. The reason that I asked this question is so
that I would know the limits of the degree that I could
enhance the behavior of the operating system.
As long as one process reading a memory location does not
ever mangle another process writing to this location, even
if the read may get mangled data when it occurs at the exact
same moment as the write, then I am good to go. It would be
even better if the read never gets mangled too. It looks
like you are saying that I can count on both of these
behaviors.
I don't think you have anything to worry about, with respect to
memory based operations.

If you want to create a semaphore, there might be a construct
in the language you're using, which makes that possible using
only the high level language. If it wasn't supported directly
by the language, or a library provided for such things, then
you can inject assembler code into your high level source, and
do it that way. Otherwise, there might not be a direct mapping
from a line of C/C++ code and say, a Test and Set instruction
on the x86 processor. People can and do inject assembler into
their programs, but when doing so, they need a damn good reason
for doing so (think of the portability issues). If there is already
a high level primitive, a library somewhere that does such
things, then someone else already solved any portability
issues for you.

Paul
Peter Olcott
2010-04-07 18:38:08 UTC
Permalink
Post by Paul
Post by Peter Olcott
As long as one process reading a memory location does not
ever mangle another process writing to this location,
even if the read may get mangled data when it occurs at
the exact same moment as the write, then I am good to go.
It would be even better if the read never gets mangled
too. It looks like you are saying that I can count on
both of these behaviors.
I don't think you have anything to worry about, with
respect to
memory based operations.
If you want to create a semaphore, there might be a
construct
in the language you're using, which makes that possible
using
only the high level language. If it wasn't supported
directly
by the language, or a library provided for such things,
then
you can inject assembler code into your high level source,
and
do it that way. Otherwise, there might not be a direct
mapping
from a line of C/C++ code and say, a Test and Set
instruction
on the x86 processor. People can and do inject assembler
into
their programs, but when doing so, they need a damn good
reason
for doing so (think of the portability issues). If there
is already
a high level primitive, a library somewhere that does such
things, then someone else already solved any portability
issues for you.
Paul
The OS invariably provides these services as function calls.

Loading...