This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27955 - share an immutable object between threads
Summary: share an immutable object between threads
Status: RESOLVED WONTFIX
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML5 spec (show other bugs)
Version: unspecified
Hardware: PC All
: P2 enhancement
Target Milestone: ---
Assignee: This bug has no owner yet - up for the taking
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard: whatwg-resolved
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-04 07:10 UTC by Charlie
Modified: 2016-10-25 09:27 UTC (History)
6 users (show)

See Also:


Attachments

Description Charlie 2015-02-04 07:10:42 UTC
"The steps will return a new object of the same type, and will permanently neuter the original object. "

It would be nice to have a way to make an arraybuffer available for reading both to a worker thread and to the main thread for reading without duplicating it in memory.

Sending it as a message will duplicate it, and transferring it will neuter it making it unavailable to the main thread.

If we can make the ArrayBuffer read only, we should be able to share it between the worker and code in the main thread while preserving thread safety.

Maybe a syntax like worker.postMessage(message, [transfers], [shares])?
Comment 1 Boris Zbarsky 2015-02-04 18:38:22 UTC
This requires JS engines to support threadsafe GC or some other threadsafe form of memory management for the arraybuffer, right?

It also requires the readonly bit, which is not so simple post-facto...
Comment 2 Charlie 2015-02-05 05:16:55 UTC
Good point that thread safe GC would be required - I don't have a good enough understanding of browser implementations to understand how difficult that would be.  Maybe a thread could be required to pass shared objects back to the original thread for them to be released?

There is already Object.freeze which works on ArrayBuffer, so i think implementing immutability may not be so much of a challenge.

I came across this interesting proposal https://gist.github.com/dherman/5401735 which may be an alternate solution.
Comment 3 Boris Zbarsky 2015-02-05 14:21:00 UTC
> There is already Object.freeze which works on ArrayBuffer

Object.freeze on an ArrayBuffer doesn't prevent mutation of its data:

  var buf = new ArrayBuffer(1);
  var view = new Uint8Array(buf);
  view[0] = 5;
  alert(view[0]);
  Object.freeze(buf);
  view[0] = 7;
  var view2 = new Uint8Array(buf);
  alert(view2[0]);

dherman's proposal is a strict superset of yours, looks like; I think it ran into implementation difficulties...
Comment 4 Arron Eicholz 2016-04-27 16:53:38 UTC
HTML5.1 Bugzilla Bug Triage: Incubation needed

This bug constitutes a request for a new feature of HTML. The current guidelines [1], rather than track such requests as bugs or issues, please create a proposal outlining the desired behavior, or at least a sketch of what is wanted (much of which is probably contained in this bug), and start the discussion/proposal in the WICG [2]. As your idea gains interest and momentum, it may be brought back into HTML through the Intent to Migrate process [3].
[1] https://github.com/w3c/html#contributing-to-this-repository
[2] https://www.w3.org/community/wicg/
[3] https://wicg.github.io/admin/intent-to-migrate.html