tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: racy acccess in kern_runq.c




> On Dec 6, 2019, at 10:21 AM, Mouse <mouse%Rodents-Montreal.ORG@localhost> wrote:
> 
> 
> [EXTERNAL EMAIL] 
> 
>> Compilers have became much more aggressive over the years.  But they
>> are allowed to be so by the C standard.  Specifically, in addition to
>> code-level re-ordering, plain accesses (loads/stores) are subject to
>> load/store fusing, tearing as well as invented loads/stores.
> 
> Then, honestly, it sounds to me as though "the latest revision of C" is
> no longer an appropriate language for writing kernels.  I see no reason
> to twist the kernel code into a pretzel to work around latitude a new
> language gives to its compilers - and that's what C11 is, a new
> language, albeit one closely related to various previous languages.
> 
> One of the prime considerations when choosing a language and/or
> compiler for building a kernel is that it produce relatively
> predictable code, for exactly this kind of reason.  If the latest C and
> the latest gcc no longer do that, then IMO they are no longer
> appropriate for writing/compiling kernels.

C11 isn't all that new, of course.  And I don't know if the rules about optimization that you object to are anywhere near that new in any case.  What seems to be the case instead is that compilers are more and more doing what the language has for a long time allowed them to do.

Consider for example "Undefined behavior -- what happened to my code?" by Wang et al. (MIT and Tsinghua University).  It describes all sorts of allowed transformations that come as a surprise to programmers.

Yes, it certainly would be possible to create a programming language with less surprising semantics.  C is not in any way shape or form a clean language with clean semantics.  But as for wanting predictable code, that is certainly doable.  Unfortunately, it requires a sufficiently deep understanding of the rules of the language.  Typical textbooks are not all that good for this, they are too superficial.  The language standard tends to be better.  But again, a problem with most programming languages is that their semantics are not well defined and/or much more complex than they should be.  Programmming in C++ is particularly scary for this reason, but C is also problematic.  For clean semantics, I like ALGOL; too bad it is no longer used, though it did at one time serve to build successful operating systems.

	paul



Home | Main Index | Thread Index | Old Index