This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Async global variable access (atomic writes?)

Other Parts Discussed in Thread: CC2640

We have 1 task that writes to some global variables at a relatively high frequency (100Hz). We have other tasks that read these global variables at random intervals. Do we need to protect these variable (via semaphore) even only 1 task writes to them, which inherently is synchronous? the other tasks only read them. Are the writes in TIRTOS atomic, so that a reading task would never end up with some bits of the variables already updated while others have not?

  • Just curious what device are you using?

    Are the global variables like a set where they all must be written/read at the same time? If they are then you would need to protect them....I would just do a Hwi_disable()....since it would be quick.

    If each global variable is independent...in other words, one does not depend on another then there should be no need to disable anything. Most hardware will write a word at a time and synchronize the hardware writes (not a software thing).
  • They are individual bool, 8, 16 and 32bit variables with no relation to each other. with a few exceptions, writing is done from only one task. Reading is done from any task.

    We are working with CC2640. Assuming that the M3 is doing atomic writes for bool, 8 and 16 bit variables, we are curious about what happens with 32bit variables? are they 2 16 bit writes, and hence, not atomic?
  • The CC2640 is an ARM M3 32-bit processor so it does it in a single 32-bit write.