I want to protect access to a couple of shared variables (circular list
pointers).
they are declared as
volatile unsigned usRead, usWrite;
I have used the atomic_add / atomic _sub functions to write to the
variables.
Two questions:
1 - Is there any need to protect reads of these variables? Can a read of a
short be interrupted and somehow corrupted? (both threads that access the
buffer run at the same priority.
2 - Can / should I safely us a atomic_add_value to get the current value as
follows?
Value = atomic_add_value( &usRead, 0);
Michael Nunan <m.nunan@ieee.ca> wrote:
I want to protect access to a couple of shared variables (circular list
pointers).
they are declared as
volatile unsigned usRead, usWrite;
I have used the atomic_add / atomic _sub functions to write to the
variables.
Two questions:
1 - Is there any need to protect reads of these variables? Can a read of a
Not on an x86 at least – dunno about PPC/MIPS etc…
short be interrupted and somehow corrupted? (both threads that access the
buffer run at the same priority.
2 - Can / should I safely us a atomic_add_value to get the current value as
follows?
Value = atomic_add_value( &usRead, 0);
Again, not if you’re on an x86…
Someone else will hafta comment on the non-x86 platforms…
Cheers,
-RK
–
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.
It is an x86 platform - Thanks.
Mike Nunan
“Robert Krten” <nospam88@parse.com> wrote in message
news:ag01cs$jcn$1@inn.qnx.com…
Michael Nunan <> m.nunan@ieee.ca> > wrote:
I want to protect access to a couple of shared variables (circular list
pointers).
they are declared as
volatile unsigned usRead, usWrite;
I have used the atomic_add / atomic _sub functions to write to the
variables.
Two questions:
1 - Is there any need to protect reads of these variables? Can a read of
a
Not on an x86 at least – dunno about PPC/MIPS etc…
short be interrupted and somehow corrupted? (both threads that access
the
buffer run at the same priority.
2 - Can / should I safely us a atomic_add_value to get the current value
as
follows?
Value = atomic_add_value( &usRead, 0);
Again, not if you’re on an x86…
Someone else will hafta comment on the non-x86 platforms…
Cheers,
-RK
–
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at > www.parse.com> .
Email my initials at parse dot com.