Forum Discussion
Altera_Forum
Honored Contributor
13 years agoproblem with mutex core
Dear all, I've created a qsys system composed of two NIOS, each one attached to its on-chip memory that contains its program. the two processors are connected to a shared RAM protected via a ...
Altera_Forum
Honored Contributor
13 years agowhile (IORD_32DIRECT(SHM,0x4) != C1) continue; Without the mutex held.
You need to use mutex to make sure nothing happens between two separate actions (eg reading 2 variables, or a read-modify-write sequence), you don't need one to just read a variable - since you can't care whether you get the old or new value. Note that the loop above relies on the compiler not moving the memory read outside the loop. IORD_32DIRECT() is (hopefully) 'asm volatile' so can't be moved, if you are reading a normal C variable (accessed uncached) you need to declare the variable volatile (eg: volatile int x;)