[webkit-dev] Atomic read/write operations and thread safety

Stephan Aßmus superstippi at gmx.de
Wed Dec 15 10:36:23 PST 2010


Am 15.12.2010 18:43, schrieb Brady Eidson:
> On Dec 15, 2010, at 8:47 AM, Brady Eidson wrote:
>> On Dec 15, 2010, at 4:28 AM, Steve Block wrote:
>> I wouldn't be surprised if there were other examples of an unprotected thread shared boolean in either WebCore or any platform's WebKit.
> In hindsight I realize my response involved assumptions about this code that were known to me but not to the general audience, so I'll followup more thoroughly.
> The boolean in question isn't both checked and set at the same time - it's not an acquired resource.  One thread sets it, the other checks it.  My belief is that this is safe for booleans, but I would love to hear where I'm wrong.

I have seen this particular technique quite often before. The only thing 
one needs to watch out for is to declare such a boolean volatile (which 
I believe this code does, if memory serves). Otherwise the thread which 
polls the condition may read from a cached location and miss the change. 
Worst that can happen on a hypothecial architecture where writing a byte 
is not atomic is that the changed condition takes affect one loop cycle 

Best regards,

More information about the webkit-dev mailing list