Re: [linux-audio-dev] Re: Shared memory

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Re: Shared memory
From: Ingo Oeser (ingo.oeser_AT_informatik.tu-chemnitz.de)
Date: Wed Jul 23 2003 - 17:26:04 EEST


Hi,

On Fri, Jul 18, 2003 at 04:14:23PM +0300, Juhana Sadeharju wrote:
> >From: Alfons Adriaensen <fons.adriaensen_AT_alcatel.be>
> >
> >I don't have your original message with the code at hand here, so
> >this may be a false alarm. Did you think of making all pointers
> >into shared memory volatile? IIRC you are testing on a counter
> >that is incremented by another process - such a small memory access
> >could easily be optimised away.
>
> And that was it!! What braindamaged compiler authors!
> In the code
>
> k = -1;
> for (;;) {
> if (k != nums[1]) {
> k = nums[1];
> fprintf(stderr,"%i\n",k);
> }
> fprintf(stderr,"g");
> }
>
> The whole if was apperently optimized away. The code printed only one
> number and a lot of "g"s. Of the two choises (1) nums[1] is updated
> elsewhere, (2) it is unnecessary code, coder just tries to be clever,
> the compiler authors selected the latter.
>
> Here is my suggestion to C standard: replace the "volatile"
> with "goaheadandoptimizetheseawayiwerejustwastingmytimeincodingthese
> theydonotmeananythingactually".
>
> Instead of forcing legitimate coders to write volatile everywhere,
> those fools who write unnecessary code should be forced to add
> the proposed qualifier.

For people like you gcc supports -fvolatile.

Your code will be really slow, but you save typing 'volatile' where the
C-Compiler needs it.

Regards

Ingo Oeser


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Wed Jul 23 2003 - 17:45:14 EEST