From:  Nick Fitzgerald <nfitzgerald@mozilla.com>
Date:  28 Jan 2017 02:01:08 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.dev.tech.js-engine.internals
Subject:  

Re: JS engine multithreading

NNTP-Posting-Host:  63.245.214.181

What an exciting time!

On Fri, Jan 27, 2017 at 7:36 AM, Brian Hackett 
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