Threading challenge: calculate fib(45) while spinning

Ali Çehreli acehreli at
Fri Oct 15 05:07:07 UTC 2021

On 10/14/21 9:17 PM, jfondren wrote:
> On Friday, 15 October 2021 at 03:54:17 UTC, Ali Çehreli wrote:
>> On 10/14/21 8:35 PM, jfondren wrote:
>>> The book, "The Go Programming Language" has this simple goroutine 
>>> example:
>> Here is one that uses receiveTimeout and OwnerTerminated:
> Very nice, replacing Thread.sleep with receiveTimeout and getting 
> graceful interruption for free. This also doesn't crash.

Cool. :)

Actually, it can be shorter by checking the return value of receiveTimeout:

       if (receiveTimeout(delay, (OwnerTerminated msg) {})) {

I didn't use this method earlier because I was afraid an unexpected 
message might make receiveTimeout return 'true'. But I've tested just 
now: Only the expected OwnerTerminated makes it return 'true'.


More information about the Digitalmars-d-learn mailing list