Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #24386

Re: How to name a function to indicate that they require calling from a critical section?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: How to name a function to indicate that they require calling from a critical section?
Date 2012-08-09 13:58 -0700
Organization None to speak of
Message-ID <lnr4rfvl3q.fsf@nuthaus.mib.org> (permalink)
References <12497759-f557-4c9a-a4f4-7bcf177b251d@googlegroups.com> <GhVUr.1067102$3s1.72445@fx12.am4>

Show all headers | View raw


Andrew Cooper <amc96@cam.ac.uk> writes:
> On 09/08/2012 02:55, celephicus@gmail.com wrote:
>> Good programmers know about critical sections, which protect shared
>> resources. Good programmers use descriptive names. I just spent a day
>> tracking down a real-time bug due to me calling a function outside a
>> critical section.
>> 
>> How would you name a function to indicate that it should only be
>> called from within a critical section? Something like
>> doStuff_critical() with the "_critical" telling you the requirement
>> for a critical section. But of course less ugly.
>
> By and large, Linux and Xen tend to use foo() and __foo(), where __foo()
> is the actual implementation, with assumptions about locks etc in the
> comments, and foo() is a wrapper which takes the correct lock(s), irq
> states etc.
>
> As a result, non-critical sections can call foo() and bar(), while a
> larger complicated critical section can take the relevant locks and call
> the required __foo() and __bar() functions.
>
> (Although it should be noted that kernel critical sections will probably
> differ widely from application level critical sections)

Identifiers starting with two underscores, or with an underscore and an
uppercase letter, are reserved to the implementation; if you define such
an identifer yourself, the behavior is undefined.

(The kernel is arguably part of the implementation, and even if it
isn't, it's probably ok for the developers to rely on certain behaviors
that aren't defined by the language standard.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to name a function to indicate that they require calling from a critical section? celephicus@gmail.com - 2012-08-08 18:55 -0700
  Re: How to name a function to indicate that they require calling from a critical section? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-09 08:31 -0400
  Re: How to name a function to indicate that they require calling from a critical section? "China Blue [Tor], Meersburg" <chine.bleu@yahoo.com> - 2012-08-09 12:24 -0700
    Re: How to name a function to indicate that they require calling from a critical section? Keith Thompson <kst-u@mib.org> - 2012-08-09 13:59 -0700
  Re: How to name a function to indicate that they require calling from a critical section? Andrew Cooper <amc96@cam.ac.uk> - 2012-08-09 21:43 +0100
    Re: How to name a function to indicate that they require calling from a critical section? Keith Thompson <kst-u@mib.org> - 2012-08-09 13:58 -0700
      Re: How to name a function to indicate that they require calling from a critical section? Andrew Cooper <amc96@cam.ac.uk> - 2012-08-09 23:11 +0100
        Re: How to name a function to indicate that they require calling from a critical section? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-09 18:22 -0400
      Re: How to name a function to indicate that they require calling from a critical section? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 08:37 -0700
        Re: How to name a function to indicate that they require calling from a critical section? Stephen Sprunk <stephen@sprunk.org> - 2012-09-07 16:01 -0500
          Re: How to name a function to indicate that they require calling from a critical section? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 18:37 -0700
            Re: How to name a function to indicate that they require calling from a critical section? Stephen Sprunk <stephen@sprunk.org> - 2012-09-30 00:17 -0500
              Re: How to name a function to indicate that they require calling from a critical section? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-17 14:24 -0800
          Re: How to name a function to indicate that they require calling   from a critical section? Ian Collins <ian-news@hotmail.com> - 2012-09-08 13:56 +1200
            Re: How to name a function to indicate that they require calling   from a critical section? Stephen Sprunk <stephen@sprunk.org> - 2012-09-30 13:45 -0500

csiph-web