Re: Simple but Strange Optimistic Concurrency Example Mark S. Miller (markm@erights.org)
Fri, 05 Feb 1999 00:23:36 -0800

Sorry, ignore the previous one, it was unnecessarily confusing. This one's cool.

? define QMaker() {
> define [qhead, qtail] := PromiseMaker()
> define cons(elem, next) {
> define pair {
> to getElem { elem }
> to getNext { next }
> }
> }
> [define enqueue(elem) {
> define [nextHead, nextTail] := PromiseMaker()
> qtail resolve(cons(elem, nextHead))
> qtail := nextTail
> null
> },
> define dequeue() {
> define result := qhead <- getElem
> qhead := qhead <- getNext
> result
> }]
> }
# value: <QMaker>

? define [enq, deq] := QMaker()
# value: [<enqueue>, <dequeue>]

? enq(3)

? def a1 := deq()
# value: <Deferred ref>

? define a2 := deq()
# value: <Deferred ref>

? a1
# value: 3

? a2
# value: <Deferred ref>

? enq(4)

? a2
# value: 4