Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2000 17:00:33 +0200
From:      Giorgos Keramidas <charon@hades.hell.gr>
To:        Mikhail Evstiounin <evstiounin@adelphia.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Volatile variables
Message-ID:  <20000113170033.F2590@hades.hell.gr>
In-Reply-To: <00f401bf5dc7$1bb3b360$fc353018@evstiouninadelphia.net.pit.adelphia.net>
References:  <00f401bf5dc7$1bb3b360$fc353018@evstiouninadelphia.net.pit.adelphia.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jan 13, 2000 at 08:07:12AM -0500, Mikhail Evstiounin wrote:
> 
> -----Original Message-----
> From: Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
> 
> 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




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