Re: [arm-gnu] Access to volatile bit-fields
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] Access to volatile bit-fields



On Thu, 2010-09-02 at 11:10 +0530, Kishore wrote:
> On Thursday 02 Sep 2010 10:24:29 am Alexander Zakharov wrote:
> > Charles,
> > 
> > I do not want dispute or argue - by the end of the day its designer's
> > choice, but I didn't spend this 15 years in the same company - I am
> > freelance consultant and each shop has its own rules, tools, procedures
> > and coding guidelines. It just happen that in current assignment
> > bitfields are part of the design SOW since shop did and is using them
> > heavily. The point though that I did try to make is that CS compiler is
> > claimed to be ARM ABI compliant and as such any deviation from ARM ABI
> > must be considered as a bug or flow (but not  a feature). By the end of
> > the day if I as a coder do declare "volatile unsigned int: 5" I really
> > mean it. Why compiler does choose access for me if I did directly
> > instruct it to do unsigned int access respective to the architecture?
> 
> Now i am not entirely convinced about this. Lets look at your example
> where you have a 5 bit variable (i) and lets say packed next to it,
> you have another 5 bit variable (j) and they both sit in the same word
> length...
> 
> Now.. in a multi threaded app, since writes to either i or j are not
> atomic, if thread A did i = 2, it would first need to read the word
> (which includes j), modify i and write back. Here any write to j
> happening at the very same moment to j in thread B can corrupt it.
> 
> In other words, writes to bitfields are non atomic and can affect
> adjacent variables and hence requires access protection around the
> whole group of variables.

Shouldn't access protection be the responsibility of the programmer?  

Regards,
James.