libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libjit] [PATCH] windows: fix race condition in _jit_thread_init()


From: Ben Noordhuis
Subject: Re: [Libjit] [PATCH] windows: fix race condition in _jit_thread_init()
Date: Tue, 21 Jan 2014 16:39:52 +0100

On Tue, Jan 21, 2014 at 3:14 PM, Aleksey Demakov <address@hidden> wrote:
> Hi Ben,
>
> Thanks for the patch. I believe there is no need for
> InterlockedCompareExchange in the case 1. It should be possible to
> spin with something like this:
>
> while (once_control != 2)
> {
>   _ReadWriteBarrier();
> }
>
> I don't have a win32 box handy to test this, could you please give it a try?
>
> Thanks,
> Aleksey

Hi Aleksey,

I *think* using _ReadWriteBarrier() like that will work in practice
but I see two caveats:

a) It's a deprecated function.

b) I'm not sure whether it's a full memory fence and compiler barrier.

The MSDN documentation says it "limits the compiler optimizations that
can remove or reorder memory accesses across the point of the call".
Note the use of "limits" instead of "eliminates".

once_control is volatile but that means the compiler is forbidden to
elide loads and stores, not that it can't move them.

Cheers,

Ben



reply via email to

[Prev in Thread] Current Thread [Next in Thread]