From:  Nick Fitzgerald <>
Date:  28 Jan 2017 02:01:08 Hong Kong Time

Re: JS engine multithreading


What an exciting time!

On Fri, Jan 27, 2017 at 7:36 AM, Brian Hackett 

> 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

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!