Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2000 06:05:38 +0100 (CET)
From:      Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Volatile variables
Message-ID:  <200001130505.GAA70510@dorifer.heim3.tu-clausthal.de>
In-Reply-To: <85jfc3$1qpv$1@atlantis.rz.tu-clausthal.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Mikhail Evstiounin <evstiounin@adelphia.net> wrote in list.freebsd-questions:
 > 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.

You _do_ need "volatile" in that case.  It is necessary for
all variables whose contents can change asynchronously, i.e.
outside of the normal program flow.  For example, this is true
for variables which are mapped to hardware registers, and for
variables which are located in a shared memory reagion (which
is shared with other processes), and for variables which are
accessed from within signal handlers.

 > 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.

No, those are different things.  The "register" qualifier is,
indeed, just a hint for the compiler that it might be worth to
hold this variable in a register if possible.  The compiler is
allowed to completely ignore it.  A compiler that doesn't even
implement that register optimization at all would still be
perfectly ANSI-compliant.

But, the "volatile" qualifier must _never_ be ignored.  It is
not just a hint.

 > 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.

But you cannot switch off multitasking.

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001130505.GAA70510>