Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Iris
Actris
Commits
cc6cd5bc
Commit
cc6cd5bc
authored
Jul 01, 2019
by
jihgfee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Producer Consumer example code
parent
33022b98
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
theories/examples/producer_consumer.v
theories/examples/producer_consumer.v
+61
-0
No files found.
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
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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