Machine-translated by Google. Questions are authored in English.
Top

Discussion

A global variable shared between a handler and a task should be declared

  • A.const, so the handler cannot modify it
  • B.register, so that access is as fast as possible
  • C.volatile, and accessed atomically or under protection
  • D.static, so that only one file can reach it

Answer: C

Correct answer: volatile, and accessed atomically or under protection

Two distinct problems must both be addressed. volatile stops the compiler caching the value in a register, so each access reads memory. It does nothing about atomicity, so a multi-byte variable can still be read half-updated - which needs a critical section or an atomic type. Neither measure substitutes for the other.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.