From d3655740cc6a8e6c4788946af412065fb52f51dc Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 31 Mar 2025 01:58:49 -0400 Subject: Deprecate do_begin/do_end --- examples/pthreads/pthreads.tm | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'examples/pthreads') diff --git a/examples/pthreads/pthreads.tm b/examples/pthreads/pthreads.tm index ab802448..cfb58aa8 100644 --- a/examples/pthreads/pthreads.tm +++ b/examples/pthreads/pthreads.tm @@ -69,15 +69,12 @@ 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_begin: q._mutex:lock() - do_end: q._mutex:unlock() - do: q._queue:insert(n) + do: q._mutex:lock(); defer: q._mutex:unlock() + q._queue:insert(n) q._cond:signal() func take(q:IntQueue -> Int): - do_begin: q._mutex:lock() - do_end: q._mutex:unlock() - do: + do: q._mutex:lock(); defer: q._mutex:unlock() repeat: if n := q._queue:pop(1): return n @@ -90,9 +87,8 @@ func main(): say_mutex := pthread_mutex_t.new() announce := func(speaker:Text, text:Text): - do_begin: say_mutex:lock() - do_end: say_mutex:unlock() - do: say("$\033[2m[$speaker]$\033[m $text") + do: say_mutex:lock(); defer: say_mutex:unlock() + say("$\033[2m[$speaker]$\033[m $text") worker := pthread_t.new(func(): say("I'm in the thread!") -- cgit v1.2.3