0

Is it safe to have one thread modify an atomic unit (e.g. a char) while the other only reads it? In an environment that permits this of course, like freertos.

I have been given some code that does just this, it uses a bool (defined as char) as a semaphore, I'm not sure why they didnt use a semaphore just for claritys sake, but then again I cant see the danger in using a char either really.

jayjay
  • 1,017
  • 1
  • 11
  • 23

1 Answers1

1

Its safe If:

1.Your processors reads a character in single instruction(which is very likely)

2.Your Processor architecture is not such that while executing a instruction external interrupt can change control flow.

3.Point 2 is vaild only if your variable is updated through ISR

Vagish
  • 2,520
  • 19
  • 32