Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Iris
Actris
Commits
cc6cd5bc
Commit
cc6cd5bc
authored
Jul 01, 2019
by
jihgfee
Browse files
Added Producer Consumer example code
parent
33022b98
Changes
1
Hide whitespace changes
Inline
Side-by-side
theories/examples/producer_consumer.v
0 → 100644
View file @
cc6cd5bc
From
stdpp
Require
Import
sorting
.
From
osiris
.
channel
Require
Import
proto_channel
proofmode
.
From
iris
.
heap_lang
Require
Import
proofmode
notation
.
From
iris
.
heap_lang
Require
Import
assert
.
From
iris
.
heap_lang
.
lib
Require
Import
spin_lock
.
From
osiris
.
utils
Require
Import
list
compare
.
Definition
qenqueue
:
val
:
=
λ
:
"q"
"v"
,
#().
Definition
qdequeue
:
val
:
=
λ
:
"q"
,
#().
Definition
qis_empty
:
val
:
=
λ
:
"q"
,
#().
Definition
enq
:
=
true
.
Definition
deq
:
=
false
.
Definition
cont
:
=
true
.
Definition
stop
:
=
false
.
Definition
some
:
=
true
.
Definition
none
:
=
false
.
Definition
dist_queue
:
val
:
=
rec
:
"go"
"q"
"pc"
"cc"
"c"
:
=
if
:
"cc"
≤
#
0
then
#()
else
if
:
recv
"c"
(* enq/deq *)
then
if
:
recv
"c"
(* cont/stop *)
then
"go"
(
qenqueue
"q"
(
recv
"c"
))
"pc"
"cc"
"c"
else
"go"
"q"
(
"pc"
-#
1
)
"cc"
"c"
else
if
:
(
qis_empty
"q"
)
then
if
:
"pc"
≤
#
0
then
send
"c"
#
stop
;;
"go"
"q"
"pc"
(
"cc"
-#
1
)
"c"
else
send
"c"
#
cont
;;
send
"c"
#
none
;;
"go"
"q"
"pc"
"cc"
"c"
else
send
"c"
#
cont
;;
send
"c"
#
some
;;
let
:
"qv"
:
=
qdequeue
"q"
in
send
"c"
(
Snd
"qv"
)
;;
"go"
(
Fst
"qv"
)
"pc"
"cc"
"c"
.
Definition
producer
:
val
:
=
rec
:
"go"
"c"
"l"
"produce"
:
=
match
:
"produce"
#()
with
SOME
"v"
=>
acquire
"l"
;;
send
"c"
#
enq
;;
send
"c"
#
cont
;;
send
"c"
"v"
;;
release
"l"
;;
"go"
"c"
"l"
"produce"
|
NONE
=>
acquire
"l"
;;
send
"c"
#
enq
;;
send
"c"
#
stop
release
"l"
end
.
Definition
consumer
:
val
:
=
rec
:
"go"
"c"
"l"
"consume"
:
=
acquire
"l"
;;
send
"c"
#
deq
;;
if
:
recv
"c"
(* cont/stop *)
then
if
:
recv
"c"
(* some/none *)
then
let
:
"v"
:
=
recv
"c"
in
release
"l"
;;
"produce"
"v"
;;
"go"
"c"
"l"
"consume"
else
release
"l"
;;
"go"
"c"
"l"
"consume"
else
release
"l"
;;
#().
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment