AnsweredAssumed Answered

STREX/LDREX question

Question asked by Legrand.Thomas.001 on Dec 4, 2013
Latest reply on Dec 4, 2013 by Legrand.Thomas.001
Hello,

I'd like to implement synchonization with LDREX / STREX.

What I don't understand is when I have multiple values to access with synchronization ...

void task1(void)
{
    ldrex var1;
    while(!strex(var1));
    do_whatever();
}
  
void task1(void)
{
    ldrex var2;
    while(!strex(var2));
    do_whatever_else();
}

(syntax is wrong but you get it).

Now what happens if task1 executes its ldrex, is preempted, context switch to task2, then task2 executes ldrex, then strex (what would be the result there ?), then context switch to task1 and task1 executes its ldrex ?

If it is unpredictable, then it means application should always use the same location for ldrex/strex, or did I miss something?

Thomas.

Outcomes