Skip to content

Commit

Permalink
ticket lock minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EkanshdeepGupta committed Nov 3, 2024
1 parent 10c098b commit 872c792
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions test/concurrent/lock/ticket-lock.rav
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ module TicketLock[R: LockResource]

inv lock_inv(l: Ref; r: R) {
own(l, agr, Agree.agree(r)) && (

exists n: Int, c: Int, b: Bool ::
own(l, next, n, 1.0)
own(l, next, n, 1.0) && n >= 0
&& own(l, curr, c, 1.0)
&& n >= 0
&& (b ? own(l, tickets, ADS.frag(IntSet.set({|c|}))) : resource(r))
&& (b ?
own(l, tickets, ADS.frag(IntSet.set({|c|}))) :
resource(r)
)
&& own(l, tickets,
ADS.auth_frag(
IntSet.set({| i: Int :: 0 <= i && i < n |}),
Expand All @@ -36,18 +37,14 @@ module TicketLock[R: LockResource]
)
}

proc create(r: R)
returns (l: Ref)
proc create(r: R) returns (l: Ref)
requires resource(r)
ensures lock_inv(l, r)
{
l := new (
next: 0,
curr: -1,
l := new (next: 0, curr: -1,
agr: Agree.agree(r),
tickets: ADS.auth_frag(
IntSet.set({||}),
IntSet.set({||})
IntSet.set({||}), IntSet.set({||})
)
);
fold lock_inv(l, r)[b := false];
Expand All @@ -68,12 +65,8 @@ module TicketLock[R: LockResource]
{!
if (res) {
fpu( l, tickets,
ADS.auth_frag(
IntSet.set({|i: Int :: 0 <= i && i < x|}), IntSet.set({||})
),
ADS.auth_frag(
IntSet.set({|i: Int :: 0 <= i && i < x+1|}), IntSet.set({|x|})
)
ADS.auth_frag( IntSet.set({|i: Int :: 0 <= i && i < x|}), IntSet.set({||}) ),
ADS.auth_frag( IntSet.set({|i: Int :: 0 <= i && i < x+1|}), IntSet.set({|x|}) )
);

fold lock_inv(l, r)[b := b, n := n+1];
Expand All @@ -86,12 +79,13 @@ module TicketLock[R: LockResource]
var acq_flag: Bool = false;

while(!acq_flag)
invariant lock_inv(l, r) && (acq_flag ?
resource(r) :
invariant lock_inv(l, r) && (
acq_flag ?
resource(r) :

own(l, tickets,
ADS.frag(IntSet.set({| x |}))
)
own(l, tickets,
ADS.frag(IntSet.set({| x |}))
)
)
{
ghost var b1: Bool;
Expand Down Expand Up @@ -139,4 +133,4 @@ module TicketLock[R: LockResource]

fold lock_inv(l, r)[b := false];
}
}
}

0 comments on commit 872c792

Please sign in to comment.