Simple but Strange Optimistic Concurrency Example

Bill Frantz frantz@communities.com
Fri, 05 Feb 1999 12:14:06 -0800


Now that's real optimism!

At 12:23 AM 2/5/99 -0800, Mark S. Miller wrote:
>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
>
>