Re: task sharing global static variables
Rahul wrote:
I was looking at the link which says the following,
http://www.netrino.com/Embedded-Systems/How-To/RTOS-Preemption-Multitasking
"When tasks share resources such as global variables, data structures,
or peripheral control and status registers, an operating system
primitive called a mutex must be used to prevent race conditions"
And i was wondering how a global variable could be shared by two
independent tasks developed in c++?
From the language point of view, there is no answer to your question
because the term "task" is not defined. However, from my experience,
a variable that resides in computer memory _can be_ just another
resource (like a device or a file), which can be shared by processes
on an operating system capable of running more than one process at
a time. If the OS/architecture supports memory addressing that does
not involve virtual space (like MS-DOS for example), then all memory
is addressible by any process (modulo some protection measures if
they exist).
The reason to pick a static/global variable for that is simple: its
address is predefined at the process start and does not change, and
its lifetime is the duration of the process. For comparison, any
automatic variable can have different place in computer memory every
time it's constructed, and the lifetime of an automatic variable is
limited to the block in which it's declared.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask