Two more multithreading questions

K

Knute Johnson

A. Bolmarcich said:
When "the first thread writes to the variable" a processor requests that
a value be written to a memory address. On some computers the request
goes into a queue and the effect of the memory write is visible to other
threads sometime later. While the memory write is being done, the first
thread continues executing.

On this type of computer architecture, whether a memory read is subsequent
to a memory write depends on the whether the read gets the value written
by the memory write. It does not depend on the global order in which
threads execute instructions.

The answer to your question: "Does volatile guarantee that the second
thread will see the value written by the first thread?", is yes, as long
as you take "some time later" being in terms of what is visible in memory
and not in terms of the global order in which the threads execute the
instruction.

The answer to your question: "Does synchronizing guarantee that the
second thread will see the value written by the first thread?" is yes,
with "some time later" being in terms of the second thread entering its
synchronized block after the first thread exited its synchronized block.

Thanks very much. I appreciate the time and effort.
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top