From owner-freebsd-questions Wed Jan 12 21: 5:45 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id 837C714BF5 for ; Wed, 12 Jan 2000 21:05:39 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.9.3/8.9.3) id GAA70510; Thu, 13 Jan 2000 06:05:38 +0100 (CET) (envelope-from olli) Date: Thu, 13 Jan 2000 06:05:38 +0100 (CET) Message-Id: <200001130505.GAA70510@dorifer.heim3.tu-clausthal.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG Reply-To: freebsd-questions@FreeBSD.ORG Subject: Re: Volatile variables X-Newsgroups: list.freebsd-questions In-Reply-To: <85jfc3$1qpv$1@atlantis.rz.tu-clausthal.de> User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (FreeBSD/3.4-19991219-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Mikhail Evstiounin 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