Yeah, I'll add some documentation to ProtectedData.h comparing it with
ExclusiveData.  ExclusiveData is nice because it provides correct
synchronization behavior by virtue of its design, whereas
ProtectedData only documents synchronization constraints that need to
be established by the code using the data.  It would be hard to use
ExclusiveData for a lot of the data we worry about synchronization
issues for, because (a) we have other ways of ensuring thread safety
besides using mutexes, and (b) even for data protected by mutexes
there isn't a 1:1 relationship between the data and the mutexes
themselves.  So, people should use ExclusiveData where possible, and
if it's not possible they should use ProtectedData to document
whatever other synchronization method is used.

Brian

On Fri, Jan 27, 2017 at 11:01 AM, Nick Fitzgerald
<nfitzger...@mozilla.com> wrote:
> What an exciting time!
>
> On Fri, Jan 27, 2017 at 7:36 AM, Brian Hackett <bhackett1...@gmail.com>
> wrote:
>>
>>
>> To help avoid threading bugs during and after this transition,
>> bug
>> 1325050 also adds a ProtectedData class, which is a template that can
>> be used on class fields to specify the conditions under which the
>> field may be accessed.  This condition will be checked in debug
>> builds.  Bug 1325050 uses ProtectedData for all the contents of
>> JSContext, JSRuntime, Zone, and ZoneGroup (and classes embedded within
>> these), and it would be nice if people could continue to use this for
>> new members in these classes going forward.  (Eventually there might
>> be an analysis to check that ProtectedData is used on all members of
>> these classes.)
>
>
> Have you taken a look at the js::ExclusiveData[0] template class? It is a
> lock that contains the protected data, so that the only way to access the
> protected data is by derefencing a magic pointer / lock guard RAII type that
> acquires the lock on construction and releases it again upon destruction.
>
> ProtectedData seems very similar, and it would be nice to have some
> exposition in the docs on why both exist (or maybe we don't need both?) and
> when one should choose ExclusiveData versus the new ProtectedData.
>
> Thanks, Brian!
>
> [0]
> http://searchfox.org/mozilla-central/rev/8fa84ca6444e2e01fb405e078f6d2c8da0e55723/js/src/threading/ExclusiveData.h#18-79
>
_______________________________________________
dev-tech-js-engine-internals mailing list
dev-tech-js-engine-internals@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals

Reply via email to