Created
April 8, 2022 09:13
-
-
Save ColmBhandal/c0fe1485b1ffa6e98ebb60de5f3f7c91 to your computer and use it in GitHub Desktop.
Slightly alternative fork/join semantics allowing a forked thread's return value to be brought back to the main thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LESSON-17-B | |
imports INT | |
imports BOOL | |
imports ID-SYNTAX | |
syntax Stmt ::= Id "=" Exp ";" [strict(2)] | |
| "return" Exp ";" [strict] | |
syntax Stmts ::= List{Stmt,""} | |
syntax Exp ::= Id | |
| Int | |
| Exp "+" Exp [seqstrict] | |
| "spawn" "{" Stmts "}" | |
| "join" Exp ";"[strict] | |
configuration <threads> | |
<thread multiplicity="*" type="Map"> | |
<id> 0 </id> | |
<k> $PGM:K </k> | |
</thread> | |
</threads> | |
<state> .Map </state> | |
<next-id> 1 </next-id> | |
rule <k> X:Id => I:Int ...</k> | |
<state>... X |-> I ...</state> | |
rule <k> X:Id = I:Int ; => . ...</k> | |
<state> STATE => STATE [ X <- I ] </state> | |
rule <k> S:Stmt Ss:Stmts => S ~> Ss ...</k> | |
rule <k> I1:Int + I2:Int => I1 +Int I2 ...</k> | |
rule <thread>... | |
<k> spawn { Ss } => NEXTID ...</k> | |
...</thread> | |
<next-id> NEXTID => NEXTID +Int 1 </next-id> | |
(.Bag => | |
<thread> | |
<id> NEXTID </id> | |
<k> Ss </k> | |
</thread>) | |
rule <thread>... | |
<k> join ID:Int ; => I ...</k> | |
...</thread> | |
(<thread> | |
<id> ID </id> | |
<k> return I:Int ; ...</k> | |
</thread> => .Bag) | |
syntax Bool ::= isKResult(K) [function, symbol] | |
rule isKResult(_:Int) => true | |
rule isKResult(_) => false [owise] | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notable changes are as follows:
| "join" Exp ";"[strict]
<k> spawn { Ss } => NEXTID ...</k>