The mutex could be emulated with a shared bool and std.atomic.cas(). That would get rid of synchronized{} blocks and would potentionally be faster.
I forgot to note that both synchronized {} blocks should also be
synchronizing on the same mutex. Right now it's two different
critical sections, so a race is still possible, i.e. while one
thread is printing the other may be removing the first printer.
Run the code several times and you'll no doubt stumble upon it.
- Re: A little of coordination for Rosettacode bearophile
- Re: A little of coordination for Rosettacode Ali Çehreli
- Re: A little of coordination for Rosettacode bearophile
- Re: A little of coordination for Rosettacode Stanislav Blinov
- Re: A little of coordination for Rosetta... Stanislav Blinov
- Re: A little of coordination for Ro... bearophile
- Re: A little of coordination fo... Stanislav Blinov
- Re: A little of coordination for Ro... Ali Çehreli
- Re: A little of coordination for Rosettacode Ali Çehreli
- Re: A little of coordination for Rosetta... bearophile
- Re: A little of coordination for Ro... Ali Çehreli
- Re: A little of coordination for Rosetta... Stanislav Blinov
- Re: A little of coordination for Ro... bearophile
- Re: A little of coordination fo... Stanislav Blinov