Note that there are some explanatory texts on larger screens.

plurals
  1. POShould access to a shared resource be locked by a parent thread before spawning a child thread that accesses it?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COMy question concerns languages like C++, where you're close to the machine level, and where a "lock" is achieved using a simple InterlockedExchange loop. I'm concerned that declaring variables "volatile" is not enough to ensure synchronization. Isn't there a difference between "atomic" and "synchronized"? Atomic operations can't be split up — and if a variable is declared volatile, the compiler won't reorder accesses to it — but can't the CPU reorder them? Especially when accessed by different cores?
      singulars
    2. COAdditional clarification: In my example, "sharedVariable = somevalue" is used to pass data to threadWhichUsesSharedVariable. It is very important that threadWhichUsesSharedVariable only accesses "sharedVariable" after it has been assigned by the parent thread.
      singulars
    3. COThe CPU can only reorder the accesses if the reordering is not visible to the program so CPU reordering should not be a concern. Much of the complexity in designing multi-core system is in ensuring that the programs never see a difference in behaviour from a single-core system.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload