synchronized vs. C volatile

SK sk at metrokings.com
Mon Aug 9 07:17:55 PDT 2010


On Mon, Aug 9, 2010 at 6:25 AM, dsimcha <dsimcha at yahoo.com> wrote:
> == Quote from SK (sk at metrokings.com)'s article
>> Does 'synchronized' mean the exact same thing as the C 'volatile'
>> qualifier when applied to basic types?
>> As in:
>> synchronized int x;
>
> They're completely different.  synchronized is basically a scoped mutex and
> applies to a statement, not a variable declaration.  I have no idea what your
> example does, but it probably shouldn't even compile.  Volatile just prevents
> certain compiler optimizations that can interfere with updates to a variable from
> other hardware besides the CPU and is useful for things like device drivers.
>
>

Sounds right to me too.  But the compiler warns about deprecated
'volatile'.  Is the warning a mistake?  Volatile has an important
place in a systems language and I'd rather not mess with tradition
here.

$ cat main.d
int main()
{
        volatile int x = 1;
        synchronized int y = 1;
        return 0;
}
$ dmd -w -wi main.d
main.d(4): volatile statements deprecated; used synchronized statements instead


More information about the Digitalmars-d mailing list