From df65e7d83e4e841fa88e3bc6058b6853c81f8560 Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Thu, 19 Jan 2017 14:18:21 -0800 Subject: [PATCH] Normative: implement SAB clause 3 --- spec.html | 120 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 29 deletions(-) diff --git a/spec.html b/spec.html index 2c7611c4d3..b5431d54e2 100644 --- a/spec.html +++ b/spec.html @@ -6300,46 +6300,104 @@

Agents

- - - + + + - - - + + + - - - + + + + + + + + + + + + + + + + + +
- Field name - - Value - - Meaning - Field nameValueMeaning
- [[LittleEndian]] - - Boolean - - The default value computed for the isLittleEndian parameter when it is needed by the algorithms GetValueFromBuffer and SetValueInBuffer. The choice is implementation dependent and should be the alternative that is most efficient for the implementation. Once the value has been observed it cannot change. - [[LittleEndian]]BooleanThe default value computed for the isLittleEndian parameter when it is needed by the algorithms GetValueFromBuffer and SetValueInBuffer. The choice is implementation dependent and should be the alternative that is most efficient for the implementation. Once the value has been observed it cannot change.
- [[CanBlock]] - - Boolean - - Determines whether the agent can block or not. - [[CanBlock]]BooleanDetermines whether the agent can block or not.
[[Signifier]]A value that admits equality testingUniquely identifies the agent within its agent cluster.
[[IsLockFree1]]BooleanTrue if and only if atomic operations on one-byte values are lock-free.
[[IsLockFree2]]BooleanTrue if and only if atomic operations on two-byte values are lock-free.
+ +

Once the values of [[Signifier]], [[IsLockFree1]], and [[IsLockFree2]] have been observed by any agent in the agent cluster they cannot change.

+ + +

The values of [[IsLockFree1]] and [[IsLockFree2]] are not necessarily determined by the hardware, but may also reflect implementation choices that can vary over time and between ECMAScript implementations.

+ +

There is no [[IsLockFree4]] property: 4-byte atomic operations are always lock-free.

+ +

Formally, atomic operations are lock-free if, infinitely often, some atomic operation finishes in a finite number of program steps. In practice, if an atomic operation is implemented with any type of lock the operation is not lock-free. Lock-free does not imply wait-free: there is no upper bound on how many machine steps may be required to complete a lock-free atomic operation.

+ +

That an atomic access of size n is lock-free does not imply anything about the (perceived) atomicity of non-atomic accesses of size n, specifically, non-atomic accesses may still be performed as a sequence of several separate memory accesses. See ReadSharedMemory and WriteSharedMemory for details.

+
+

An agent is a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation.

+ +

Agent Clusters

+ +

An agent cluster is a maximal set of agents that can communicate by operating on shared memory.

+ + +

Programs within different agents may share memory by unspecified means. At a minimum, the backing memory for SharedArrayBuffer objects can be shared among the agents in the cluster.

+ +

There may be agents that can communicate by message passing that cannot share memory; they are never in the same agent cluster.

+
+ +

Every agent belongs to exactly one agent cluster.

+ + +

The agents in a cluster need not all be alive at some particular point in time. If agent A creates another agent B, after which A terminates and B creates agent C, the three agents are in the same cluster if A could share some memory with B and B could share some memory with C.

+
+ +

All agents within a cluster must have the same value for the [[LittleEndian]] property in their respective Agent Records.

+ + +

If different agents within an agent cluster have different values of [[LittleEndian]] it becomes hard to use shared memory for multi-byte data.

+
+ +

All agents within a cluster must have the same values for the [[IsLockFree1]] property in their respective Agent Records; similarly for the [[IsLockFree2]] property.

+ +

All agents within a cluster must have different values for the [[Signifier]] property in their respective Agent Records.

+ + + +

An embedding may deactivate (stop forward progress) or activate (resume forward progress) an agent without the agent's knowledge or cooperation. If the embedding does so, it must not leave some agents in the cluster active while other agents in the cluster are deactivated indefinitely.

+ + +

The purpose of the preceding restriction is to avoid a situation where an agent deadlocks or starves because another agent has been suspended. For example, if a DOM SharedWorker shares memory with a regular worker, and the regular worker is suspended while it holds a lock (because the web page the regular worker is in is pushed into the window history), and the SharedWorker tries to acquire the lock, then the SharedWorker will be blocked until the regular worker wakes up again, if ever. Meanwhile other workers trying to access the SharedWorker from other web pages will starve.

+ +

The implication of the restriction is that it will not be possible to share memory between agents that don't belong to the same suspend/wake collective within the embedding.

+
+ +

An embedding may terminate an agent without any of the agent's cluster's other agents' prior knowledge or cooperation. If an agent is terminated not by programmatic action of its own or of another agent in the cluster but by forces external to the cluster, then the embedding must choose one of two strategies: Either terminate all the agents in the cluster, or provide reliable APIs that allow the agents in the cluster to coordinate so that at least one remaining member of the cluster will be able to detect the termination, with the termination data containing enough information to identify the agent that was terminated.

+ + +

Examples of that type of termination are: operating systems or users terminating agents that are running in separate processes; the embedding itself terminating an agent that is running in-process with the other agents when per-agent resource accounting indicates that the agent is runaway.

+
+ + +

An agent cluster is a specification mechanism and need not correspond to any particular artefact of an ECMAScript implementation.

+
+
+

Forward Progress

For an agent to make forward progress is for it to perform an evaluation step according to this specification.

@@ -6347,8 +6405,12 @@

Forward Progress

The shared memory proposal introduces a method for blocking in the Atomics.wait method.

-

Implementations must ensure that every unblocked agent with a dedicated executing thread eventually makes forward progress.

-

Implementations must ensure that, in a set of agents that share an executing thread, one agent eventually makes forward progress.

+

Implementations must ensure that:

+