From 7a172be6213839a3d023ba21c3bafd7540a4bfe8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 31 Mar 2025 02:11:03 -0400 Subject: Remove threads and mutexed data from the language in favor of a module-based approach --- test/optionals.tm | 39 ------------------------------- test/threads.tm | 70 ------------------------------------------------------- 2 files changed, 109 deletions(-) delete mode 100644 test/threads.tm (limited to 'test') 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! -- cgit v1.2.3