A thread safe routine should be careful of the following:

  • Keep routine non-reentrant
  • Avoid using “static” variables. If not protected, you might find unwanted results
  • Use atomic variables for things like states, shared variables (locks such as mutex, semaphore, spinlock are expensive)
  • Always allocate big local variable (> 10k) on heap
Advertisements