From owner-freebsd-questions Thu Jan 13 14:36:14 2000 Delivered-To: freebsd-questions@freebsd.org Received: from mx2.x-treme.gr (mx2.x-treme.gr [212.120.192.15]) by hub.freebsd.org (Postfix) with ESMTP id 997101559F for ; Thu, 13 Jan 2000 14:36:08 -0800 (PST) (envelope-from keramida@diogenis.ceid.upatras.gr) Received: from hades.hell.gr (pat34.x-treme.gr [212.120.197.226]) by mx2.x-treme.gr (8.9.3/8.9.3/IPNG-ADV-ANTISPAM-0.1) with ESMTP id AAA09688; Fri, 14 Jan 2000 00:35:46 +0200 Received: (from charon@localhost) by hades.hell.gr (8.9.3/8.9.3) id RAA03636; Thu, 13 Jan 2000 17:00:33 +0200 (EET) (envelope-from keramida@diogenis.ceid.upatras.gr) Date: Thu, 13 Jan 2000 17:00:33 +0200 From: Giorgos Keramidas To: Mikhail Evstiounin Cc: freebsd-questions@freebsd.org Subject: Re: Volatile variables Message-ID: <20000113170033.F2590@hades.hell.gr> Reply-To: keramida@ceid.upatras.gr References: <00f401bf5dc7$1bb3b360$fc353018@evstiouninadelphia.net.pit.adelphia.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre3i In-Reply-To: <00f401bf5dc7$1bb3b360$fc353018@evstiouninadelphia.net.pit.adelphia.net> Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, Jan 13, 2000 at 08:07:12AM -0500, Mikhail Evstiounin wrote: > > -----Original Message----- > From: Oliver Fromme > > Could you explain me how it helps in your example? I pointed, that > you can get signal between two assembler commands and it does > destroys all your assumptions. As I said in a previous posting a few minutes ago, Oliver did not use that example of mine for supporting his notion of `volatile'. Not only because it was not his example, but because the example was ill fortuned since I did not use `cc -O2 -S hello.c' when converting the C source to assembler. When I tried this a few seconds ago it gave: % cat hello.c volatile int k; int main (void) { k = 0; k = 1; return 0; } % cc -O2 -S hello.c % cat hello.s .text .p2align 2 .globl main .type main,@function main: pushl %ebp movl %esp,%ebp movl $0,k movl $1,k xorl %eax,%eax leave ret .Lfe1: .size main,.Lfe1-main .comm k,4,4 which does in fact use what you suggested in a previous posting, the instructions that set `k' to 1 are converted to `movl $1,k' which I can assume that executes atomically as far as signals are concerned. It seems that `volatile' is effective in GNU C only when optimizations are enabled, because without optimizations the code is, well..., unoptimal, and can cause great troubles when used with signals ;) -- Giorgos Keramidas, < keramida @ ceid . upatras . gr > "What we have to learn to do, we learn by doing." [Aristotle] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message