From owner-freebsd-questions Thu Jan 13 18:59: 6 2000 Delivered-To: freebsd-questions@freebsd.org Received: from alpha.pit.adelphia.net (alpha.pit.adelphia.net [24.48.44.2]) by hub.freebsd.org (Postfix) with ESMTP id 9FEBB14EF6 for ; Thu, 13 Jan 2000 18:59:03 -0800 (PST) (envelope-from evstiounin@adelphia.net) Received: from evstiouninadelphia (surf15-169.pit.adelphia.net [24.48.53.169]) by alpha.pit.adelphia.net (8.9.2/8.9.2) with SMTP id VAA07894; Thu, 13 Jan 2000 21:58:50 -0500 (EST) Message-ID: <010701bf5e3b$a6dac5e0$a9353018@evstiouninadelphia.net.pit.adelphia.net> From: "Mikhail Evstiounin" To: Cc: Subject: Re: Volatile variables Date: Thu, 13 Jan 2000 22:01:27 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG -----Original Message----- From: Giorgos Keramidas To: Mikhail Evstiounin > >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 I know, I am bad, but, please don't kill me:-( I appologized acouple hours ago. It's my fault. >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; Could you try to use atomic instead of int - I don't have FreeBSD under my hand and just want to see a generated code. > 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 ;) We should ask about this gcc team. It's possible, that this is a different understanding of vilotile. Because, I still do not agree with your usage/understanding - I am still thinking that it should be used, if value of a vriable could be changed in ways not defined by the language. And sighandler will change it within a way defined by the language - assigments. But usage of a global resource from different async processes requires synchronization and this is a totally different problem. Take a look at two threads running simultineosly on two CPU, sharing an access to the same variable - vilotile is not going to help you. In my mind, sighandler is async process, but it accesses variable in a way defined by the language. From my point of view, two different problems were mixed and, as a result, totally wrong way to solve them were chosen. I was trying to emphasize only this part, but didn't myself clear enough. Sorry. > >-- >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