Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2000 22:01:27 -0500
From:      "Mikhail Evstiounin" <evstiounin@adelphia.net>
To:        <keramida@ceid.upatras.gr>
Cc:        <freebsd-questions@freebsd.org>
Subject:   Re: Volatile variables
Message-ID:  <010701bf5e3b$a6dac5e0$a9353018@evstiouninadelphia.net.pit.adelphia.net>

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

-----Original Message-----
From: Giorgos Keramidas <charon@hades.hell.gr>
To: Mikhail Evstiounin <evstiounin@adelphia.net>


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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?010701bf5e3b$a6dac5e0$a9353018>