Fiber is better than go's goroutine?

Sean Kelly via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 27 13:37:25 PDT 2014


On Sunday, 26 October 2014 at 16:12:29 UTC, Sean Kelly wrote:
> On Sunday, 26 October 2014 at 15:35:28 UTC, FrankLike wrote:
>> Many persons like go's goroutine,but how about is the same 
>> thing in D?
>
> We need a better Scheduler.  It's something I've been planning 
> to do, but had held off until the base Scheduler proposal was 
> accepted.  At that point I think D will be in pretty good 
> shape.  The FiberScheduler is a good start though, if you want 
> to experiment.

One thing I just ran into while working on MultiScheduler is that 
if a spawned thread is holding a lock when it yields, and by 
yielding is picked up and executed by another thread, Bad Things 
happen.  In hindsight this sees obvious, but it's something I 
hadn't considered until now.

I think this shouldn't be much of a concern given that you're not 
supposed to be doing any more inside a mutex than necessary, and 
so things like sending and receiving messages should never occur 
within a synchronized block anyway, but it's an important issue 
to be aware of.  I'm still mulling over whether it's worth the 
cost to try and detect this and throw an Error.

In related news, MultiScheduler is coming along nicely.  It's 
already functional, and I'm polishing the implementation.  I 
found the issue with mutexes because of an implementation bug in 
MultiScheduler, since fixed, so this shouldn't be a concern for 
normal use.  This scheduler is still pretty basic, so an even 
fancier one may be worth creating that tracks execution times and 
such to ensure progress in the presence of misbehaved user 
threads.


More information about the Digitalmars-d mailing list