[Ffmpeg-devel] alsa input / output

Trent Piepho xyzzy
Mon Mar 26 00:23:36 CEST 2007

On Sun, 25 Mar 2007, matthieu castet wrote:
> Do you have a better example, because AFAIK pointer are considered as
> volatile data ?

Not sure exactly what you mean, but I don't think that's true.  For example:

int *spinlock;
void foo() { while(*spinlock) ; }

gcc will compile this too:
        movl    spinlock, %eax  # spinlock, spinlock
        movl    (%eax), %eax    #* spinlock,
        testl   %eax, %eax      #
        jne     .L6     #,
        jmp     .L6     #  this is infinite loop

For those that don't read asm, that's the same as:

void foo() { if(*spinlock) for(;;) ; }

Of course volatile isn't enough to create a real SMP safe spinlock on a
modern cpu.  gcc does do (or is intended to do anyway) what it's supposed
to do for volatile, as volatile _is_ defined by C99 et al.  The definition
just isn't one that lets you create a smp safe spinlock.  One could say the
definition of volatile should be different, but it's not, and there is no
way one can create SMP safe spinlocks (or mutexes, or semaphores, or
whatever) with just plain C.

More information about the ffmpeg-devel mailing list