Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jan 2000 22:02:43 -0500
From:      "Mikhail Evstiounin" <evstiounin@adelphia.net>
To:        <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Volatile variables
Message-ID:  <00b101bf5d72$a95c0be0$fc353018@evstiouninadelphia.net.pit.adelphia.net>

next in thread | raw e-mail | index | archive | help

-----Original Message-----
From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
To: freebsd-questions@FreeBSD.ORG <freebsd-questions@FreeBSD.ORG>
Date: Wednesday, January 12, 2000 9:47 PM
Subject: Re: Volatile variables


>Mikhail Evstiounin <evstiounin@adelphia.net> wrote in
list.freebsd-questions:
> > [...]
> > Like I told above it should be done in atomic way, but vilotale means -
> > avoid
> > optimiozations.
>
>"volatile" does not mean that the compiler should not optimize.
>It only means that the compiler must not make certain
>assumptions about a variable, and that its value may be read or


agreed, I wasn't clear, but again - back to standard -
"so that aggresive optimization must be avoided".

>written asynchronously, i.e. its value might not be consistent


should add  - in ways not specified by the language. You can chage a
global variable in different threads - asynchroniosly, you should
synchromize
access - you don't need vilotile here.

>between statements.  No more, no less.  Of course, this
>inhibits certain types of optimizations, naturally.
>
> > And again it's a hint - just a hint. Some aggresive
> > optimizers
> > could ignore it.
>
>No!  A C compiler must not ignore the "volatile" qualifier.
>It's the compiler's job to make sure that the program is not
>working with a "stale" variable value.


I was not talking aboutt "ignore", I was talking about "hint", ehich
in my mind means - if you can provide protection, you can use
aggresive optimization. Your example still leaves variable
in a "stale" mode. And yes, it's a compiler to make sure that the
program works, but there are different ways. In my mind, it's pretty close
to register specifier - compiler will try to allocate variablue in a
registere,
but if there is not enough registers then compiler will allocate variable
in memory. It's still works, but not as fast as author wanted. The same is
with vilotile - if there is a way to provide an "atomic" way for some part
of code then compiler can use some pretty aggresive optimizations.

>
> > For example, if commands cli/sti could be used by compiler
> > and works like it  work in 8086, optimizer could do the following:
>
>Yeah, it could, but this is UNIX, not DOS.  :)
>

It doesn't matter, it was just an example, and BTW, you can configure
segments in a way when it would be true. And even in Unix world you can
use sigmask.

>Regards
>   Oliver
>
>--
>Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
>(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)
>
>"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
>                                         (Terry Pratchett)
>
>
>To Unsubscribe: send mail to majordomo@FreeBSD.org
>with "unsubscribe freebsd-questions" in the body of the message



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?00b101bf5d72$a95c0be0$fc353018>