From 2ecb5fe885042ca6c25ee0a3e3da070ddec9e07e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 11 Aug 2024 14:47:34 -0400 Subject: Add channels and threads --- test/text.tm | 2 +- test/threads.tm | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/threads.tm (limited to 'test') diff --git a/test/text.tm b/test/text.tm index 27c8c08a..4051a16f 100644 --- a/test/text.tm +++ b/test/text.tm @@ -1,6 +1,6 @@ func main(): >> str := "Hello Amélie!" - | Testing strings like {str} + //! Testing strings like {str} >> str:upper() = "HELLO AMÉLIE!" diff --git a/test/threads.tm b/test/threads.tm new file mode 100644 index 00000000..33685103 --- /dev/null +++ b/test/threads.tm @@ -0,0 +1,32 @@ +enum Job(Increment(x:Int), Decrement(x:Int)) + +func main(): + jobs := |:Job| + results := |:Int| + >> thread := Thread.new(func(): + //! In another thread! + while yes: + when jobs:pop() is Increment(x): + >> results:push(x+1) + is Decrement(x): + >> results:push(x-1) + ) + + >> jobs:push(Increment(5)) + >> jobs:push(Decrement(100)) + + >> results:pop() + = 6 + + >> jobs:push(Increment(1000)) + >> results:pop() + = 99 + + >> results:pop() + = 1001 + + //! Canceling... + >> thread:cancel() + //! Joining... + >> thread:join() + //! Done! -- cgit v1.2.3