aboutsummaryrefslogtreecommitdiff
path: root/examples/pthreads/pthreads.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 14:20:18 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 14:20:18 -0400
commit2bb2ff871fa1761478442bec5f6a32c9428360a1 (patch)
tree9b73df7a0c50c02353ae7bca7c2cd54788ef0077 /examples/pthreads/pthreads.tm
parent59845e610f2c90474f34079d27b5f1e07071ded4 (diff)
Change method calls to use `foo.baz()` instead of `foo:baz()`
Diffstat (limited to 'examples/pthreads/pthreads.tm')
-rw-r--r--examples/pthreads/pthreads.tm32
1 files changed, 16 insertions, 16 deletions
diff --git a/examples/pthreads/pthreads.tm b/examples/pthreads/pthreads.tm
index fb79e822..3be052b4 100644
--- a/examples/pthreads/pthreads.tm
+++ b/examples/pthreads/pthreads.tm
@@ -69,18 +69,18 @@ struct IntQueue(_queue:@[Int], _mutex:@pthread_mutex_t, _cond:@pthread_cond_t):
return IntQueue(@initial, pthread_mutex_t.new(), pthread_cond_t.new())
func give(q:IntQueue, n:Int):
- do: q._mutex:lock()
- q._queue:insert(n)
- q._mutex:unlock()
- q._cond:signal()
+ do: q._mutex.lock()
+ q._queue.insert(n)
+ q._mutex.unlock()
+ q._cond.signal()
func take(q:IntQueue -> Int):
- do: q._mutex:lock()
- n := q._queue:pop(1)
+ do: q._mutex.lock()
+ n := q._queue.pop(1)
while not n:
- q._cond:wait(q._mutex)
- n = q._queue:pop(1)
- q._mutex:unlock()
+ q._cond.wait(q._mutex)
+ n = q._queue.pop(1)
+ q._mutex.unlock()
return n!
fail("Unreachable")
@@ -90,29 +90,29 @@ func main():
say_mutex := pthread_mutex_t.new()
announce := func(speaker:Text, text:Text):
- do: say_mutex:lock()
+ do: say_mutex.lock()
say("$\033[2m[$speaker]$\033[m $text")
- say_mutex:unlock()
+ say_mutex.unlock()
worker := pthread_t.new(func():
say("I'm in the thread!")
repeat:
announce("worker", "waiting for job")
- job := jobs:take()
+ job := jobs.take()
result := job * 10
announce("worker", "Jobbing $job into $result")
- results:give(result)
+ results.give(result)
announce("worker", "Signaled $result")
)
for i in 10:
announce("boss", "Pushing job $i")
- jobs:give(i)
+ jobs.give(i)
announce("boss", "Gave job $i")
for i in 10:
announce("boss", "Getting result...")
- result := results:take()
+ result := results.take()
announce("boss", "Got result $result")
- >> worker:cancel()
+ >> worker.cancel()