aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-31 02:11:03 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-31 02:11:03 -0400
commit7a172be6213839a3d023ba21c3bafd7540a4bfe8 (patch)
tree5646ba0e4c0690fe64711fb77658308541de695b /test
parentd3655740cc6a8e6c4788946af412065fb52f51dc (diff)
Remove threads and mutexed data from the language in favor of a
module-based approach
Diffstat (limited to 'test')
-rw-r--r--test/optionals.tm39
-rw-r--r--test/threads.tm70
2 files changed, 0 insertions, 109 deletions
diff --git a/test/optionals.tm b/test/optionals.tm
index 58f1b98c..02817441 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -61,18 +61,6 @@ func maybe_c_string(should_i:Bool->CString?):
else:
return none
-func maybe_thread(should_i:Bool->Thread?):
- if should_i:
- return Thread.new(func(): pass)
- else:
- return none
-
-func maybe_mutexed(should_i:Bool->mutexed(Bool)?):
- if should_i:
- return mutexed no
- else:
- return none
-
func main():
>> 5?
= 5?
@@ -244,33 +232,6 @@ func main():
fail("Truthy: $nope")
else: !! Falsey: $nope
- do:
- !! ...
- !! Threads:
- >> yep := maybe_thread(yes)
- # No "=" test here because threads use addresses in the text version
- >> nope := maybe_thread(no)
- = none : Thread
- >> if yep: >> yep
- else: fail("Falsey: $yep")
- >> if nope:
- fail("Truthy: $nope")
- else: !! Falsey: $nope
-
- do:
- !! ...
- !! Mutexed:
- >> yep := maybe_mutexed(yes)
- # No "=" test here because threads use addresses in the text version
- >> nope := maybe_mutexed(no)
- = none : mutexed(Bool)
- >> if yep: >> yep
- else: fail("Falsey: $yep")
- >> if nope:
- fail("Truthy: $nope")
- else: !! Falsey: $nope
-
-
if yep := maybe_int(yes):
>> yep
= 123
diff --git a/test/threads.tm b/test/threads.tm
deleted file mode 100644
index adf7784a..00000000
--- a/test/threads.tm
+++ /dev/null
@@ -1,70 +0,0 @@
-enum Job(Increment(x:Int), Decrement(x:Int))
-
-func main():
- do:
- >> nums := mutexed [10, 20, 30]
- holding nums:
- >> nums[]
- = [10, 20, 30]
- nums:insert(40)
-
- holding nums:
- >> nums[]
- = [10, 20, 30, 40]
-
-
- jobs := mutexed [Job.Increment(5)]
-
- results := mutexed [:Int]
-
- >> thread := Thread.new(func():
- !! In another thread!
- repeat:
- job := holding jobs: (jobs:pop(1) or stop)
- when job is Increment(x):
- holding results: results:insert(x + 1)
- is Decrement(x):
- holding results: results:insert(x - 1)
- )
-
- holding jobs:
- jobs:insert(Decrement(100))
- jobs:insert(Decrement(200))
- jobs:insert(Decrement(300))
- jobs:insert(Decrement(400))
- jobs:insert(Decrement(500))
- jobs:insert(Decrement(600))
- jobs:insert(Increment(1000))
-
- dequeue_result := func():
- result := none:Int
- repeat:
- result = (holding results: results:pop(1))
- stop if result
- sleep(0.00001)
- return result!
-
- >> dequeue_result()
- = 6
- >> dequeue_result()
- = 99
-
- >> dequeue_result()
- = 199
- >> dequeue_result()
- = 299
- >> dequeue_result()
- = 399
- >> dequeue_result()
- = 499
- >> dequeue_result()
- = 599
-
- >> dequeue_result()
- = 1001
-
- !! Canceling...
- >> thread:cancel()
- !! Joining...
- >> thread:join()
- !! Done!