Next: , Previous: Rendezvous communication channels, Up: Concurrent ML


5.4.5 Rendezvous-synchronized cells

5.4.5.1 Placeholders: single-assignment cells

Placeholders1 are single-assignment cells on which readers block until they are assigned.

Note: These placeholders are disjoint from and incompatible with the placeholder mechanism provided in the placeholders structure, and attempts to apply operations on one to values of the other are errors.

— procedure: make-placeholder [id] –> empty placeholder
— procedure: placeholder? object –> boolean

Make-placeholder creates and returns a new, empty placeholder. Id is used only for debugging purposes; it is included in the printed representation of the placeholder. Placeholder? is the disjoint type predicate for placeholders.

— procedure: placeholder-value-rv placeholder –> rendezvous
— procedure: placeholder-value placeholder –> value (may block)

Placeholder-value-rv returns a rendezvous that, when synchronized, becomes enabled when placeholder has a value, with that value. Placeholder-value has the effect of immediately synchronizing such a rendezvous, and it returns the value directly, but possibly after blocking.

— procedure: placeholder-set! placeholder value –> unspecified

Sets placeholder's value to be value, and enables all rendezvous for placeholder's value with that value. It is an error if placeholder has already been assigned.

5.4.5.2 Jars: multiple-assignment cells

Jars2 are multiple-assignment cells on which readers block. Reading from a full jar has the effect of emptying it, enabling the possibility of subsequent assignment, unlike placeholders; and jars may be assigned multiple times, but, like placeholders, only jars that are empty may be assigned.

— procedure: make-jar [id] –> empty jar
— procedure: jar? object –> boolean

Make-jar creates and returns a new, empty jar. Id is used only for debugging purposes; it is included in the printed representation of the jar. Jar? is the disjoint type predicate for jars.

— procedure: jar-take-rv jar –> rendezvous
— procedure: jar-take jar –> value (may block)

Jar-take-rv returns a rendezvous that, when synchronized, becomes enabled when jar has a value, which is what value the rendezvous becomes enabled with; when that rendezvous is enabled, it also removes the value from jar, putting the jar into an empty state. Jar-take has the effect of synchronizing such a rendezvous, may block because of that, and returns the value of the jar directly, not a rendezvous.

— procedure: jar-put! jar value –> unspecified

Jar-put! puts value into the empty jar jar. If any taker rendezvous are waiting, the first is enabled with the value, and the jar is returned to its empty state; otherwise, the jar is put in the full state. Jar-put! is an error if applied to a full jar.


Footnotes

[1] Called I-variables in Reppy's CML, and I-structures in ID-90.

[2] Termed M-variables in Reppy's CML.