mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Francis Moreau" <francis.moro@gmail.com>
To: "Chris Snook" <csnook@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Question about C language.
Date: Mon, 24 Mar 2008 09:24:06 +0100	[thread overview]
Message-ID: <38b2ab8a0803240124j61a78649v45533a551f2f7da9@mail.gmail.com> (raw)
In-Reply-To: <47E60702.30302@redhat.com>

Hello,

On Sun, Mar 23, 2008 at 8:30 AM, Chris Snook <csnook@redhat.com> wrote:
>  > I know it's a bit out of topic but this is something I need to clarify for
>  > writing a Linux driver... hope you don't mind.
>  >
>  > In my driver I have a global variable that controls a loop such as:
>  >
>  > int my_condition;
>  >
>  > void change_my_condition(int new)
>  > {
>  >     my_condition = new;
>  > }
>  >
>  > int foo(void)
>  > {
>  >     /* irqs are disabled */
>  >     my_condition = 1;
>  >     do {
>  >         ....
>  >         local_irq_enable();
>  >         cpu_sleep();
>  >         local_irq_disable();
>  >
>  >    } while (my_condition);
>  >
>  > }
>  >
>  > This variable is modified by an interrupt handler define in another file
>  > by using 'change_my_condition' function.
>  >
>  > By reading the ISO C99 specification, I _think_ that I needn't any
>  > kind of barrier
>  > or even use the volatile type qualifier for my_condition variable to make a true
>  > access to 'my_condition' in the controlling expression of the while, but I'm not
>  > sure.
>  >
>  > Coud anybody confirm ?
>  >
>  > Thanks,
>
>  Even volatile may be insufficient with some architecture/compiler
>  combinations.  You should use explicit barriers wherever you need them,
>  or Bad Things will happen.
>

Really ?

Could you give me some details please ?

As I said previously, I don't think I need any barriers here because this code
doesn't have any reordering issues and futhermore only one CPU will be up
at this time.

Actually the only issue I can see is about compiler aliases. I don't know if
in that case it could use an alias for 'my_condition'. Looking at the code, it
would be a bad idea but I can't find anything about this in the C specification.
The C spec talks about sequence points but I'm really confused when reading
that part...

Thanks
-- 
Francis

      parent reply	other threads:[~2008-03-24  8:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-21 15:46 Francis Moreau
2008-03-23  7:30 ` Chris Snook
2008-03-23  7:32   ` Chris Snook
2008-03-24  8:25     ` Francis Moreau
2008-03-24  8:24   ` Francis Moreau [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38b2ab8a0803240124j61a78649v45533a551f2f7da9@mail.gmail.com \
    --to=francis.moro@gmail.com \
    --cc=csnook@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®