Global Variable Safety with Multi-tasking
- Posted by cp Aug 13, 2012
- 1624 views
What technique (if any) do I need to use to ensure safety when using global variables with real-time tasks?
For example two real-time tasks need to access a global sequence. Task A will read from configuration file every few minutes and may update (add or remove) some elements in the global sequence. Task B will loop thru the elements in the global sequence performing some operations.
If task B yields to task A and task A changes the number of elements in the sequence, when execution returns to task B that could cause a problem with the "for" loop count?
Do I need to ensure that task B only yields after the for loop is complete to be safe? something like:
procedure task_B() while 1 for i = 1 to length(seqGlobal) do DoSomeStuff(seqGlobal[i]) end for task_yield() end while end procedure
Or are their other options which will allow yield more often within the for loop?
thanks, Casey