[webkit-dev] Atomic read/write operations and thread safety
beidson at apple.com
Wed Dec 15 11:17:20 PST 2010
On Dec 15, 2010, at 11:11 AM, Steve Block wrote:
> Thanks for the reply Brady.
>> 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.
> I don't follow. If it's set from one thread and checked from another
> thread without locks, how can you guarantee this (other than with
> application logic)?
I don't understand your question - "how can you guarantee this?"
>> Additionally, while there isn't a guard specifically around the boolean, there is the "m_syncLock" Mutex
>> which is implicitly guarding operations on this bool, so the "thread safety of a bool?" argument becomes
>> somewhat moot.
> Ah, so you're saying that there's application logic using m_syncLock
> to prevent the boolean from being written and read at the same time? I
> didn't spot that.
It doesn't matter if it's written and read at the same time in this case - but after every write on the main thread, the background thread is signaled to read, so that read will always happen after the write.
More information about the webkit-dev