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 ago --- Quote Start --- while (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;) --- Quote End --- Hi, I can't solve the problem the first cpu writes 4 in @ 0x0 in the second cpu: while (IORD_32DIRECT(SHM,0x0) != 4) {printf("waiting \n");} printf("data read = %d \n",IORD_32DIRECT(SHM,0x0) ); The cpu2 display a series of waiting in the console, this means that it doexn't read the right value written by cpu1 So , please what can i do?