From bc4fb5ef94111c8e8f51f4b9e8ed48b08f120f4d Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 2 Nov 2018 00:11:59 +0000 Subject: [PATCH] Ensure patched assertions are added before being removed, to avoid glitching --- syndicate/HOWITWORKS.md | 4 ++++ syndicate/dataspace.rkt | 5 ++++- syndicate/examples/box-and-client.rkt | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/syndicate/HOWITWORKS.md b/syndicate/HOWITWORKS.md index 2a824c0..01768d7 100644 --- a/syndicate/HOWITWORKS.md +++ b/syndicate/HOWITWORKS.md @@ -458,6 +458,10 @@ check followed by zero or more (move, check) pairs. removeAssertion :: Index -> V -> 1 removeAssertion index v = adjustAssertion index v -1 +Care must be taken when applying entire *patches* to ensure that added +assertions are processed before removed assertions; otherwise, actors +will observe glitching in certain cases. + **Definition.** The procedure `sendMessage` delivers a message `v` to event handlers in the given index. diff --git a/syndicate/dataspace.rkt b/syndicate/dataspace.rkt index 690978d..6e56b5f 100644 --- a/syndicate/dataspace.rkt +++ b/syndicate/dataspace.rkt @@ -368,15 +368,18 @@ ;; (for [((a c) (in-bag/count ds-assertions))] (log-info " . ~v = ~v" a c)) ;; (for [((a c) (in-bag/count delta))] (log-info " → ~v = ~v" a c)) (define rt (dataspace-routing-table ds)) + (define pending-removals '()) (define new-cleanup-changes (for/fold [(cleanup-changes (actor-cleanup-changes ac))] [((a count) (in-bag/count delta))] (match (bag-change! ds-assertions a count) - ['present->absent (remove-assertion! rt a)] + ['present->absent (set! pending-removals (cons a pending-removals))] ['absent->present (add-assertion! rt a)] ;; 'absent->absent absurd ['present->present (void)]) ;; i.e. no visible change (define-values (updated-bag _summary) (bag-change cleanup-changes a (- count))) updated-bag)) + (for [(a (in-list pending-removals))] + (remove-assertion! rt a)) (set-actor-cleanup-changes! ac new-cleanup-changes))) (define (run-scripts! ds) diff --git a/syndicate/examples/box-and-client.rkt b/syndicate/examples/box-and-client.rkt index a52fd44..00d697d 100644 --- a/syndicate/examples/box-and-client.rkt +++ b/syndicate/examples/box-and-client.rkt @@ -16,4 +16,6 @@ (log-info "client: box has gone")) (on (asserted (box-state $v)) (log-info "client: learned that box's value is now ~v" v) - (send! (set-box (+ v 1))))) + (send! (set-box (+ v 1)))) + (on (retracted (box-state _)) + (log-info "client: box state disappeared")))