[Mono-dev] Mono Continuations and MicroThreads

Tomi Valkeinen tomba at bat.org
Fri Apr 21 04:20:18 EDT 2006


> The perfect thread scheduler is the one that give the same execution period 
> time for all threads :)
> So a first ( incomplete ) idea is coming to me :
> If :
> * You define a maximum time of execution foreach microthread.
> * the scheduler call the microthread run method.
> * An OS thread loop until the max time is reached for the current microthread 
> or the current microthread returns. If the microthread didn't return before 
> the defined max time, the scheduler force this microthread to save his stack 
> and it switch to an another microthread.

I have to disagree here. The whole idea in microthreads is that they are 
non-preemptive, ie. the microthread has to yield willingly. This way there 
are no concurrency problems, as the state of the program is always known.

If the microthreads were preemptive as you describe, the execution of a 
thread could be interrupted at any time, thus the state of the program 
would be unknown. This would mean that you'd have to use locks/mutexes/etc 
to keep datastructures intact. And then we'd have threads similar to OS 
threads, and I think the OS threads would do the job better.

That said, it could be possible to implement preemptive microthreads (I'm 
not sure about this, I haven't thought it through). However, that would 
need modifications to the native implementation. And as I described above, 
I don't really understand why this would be in any way a good thing =).


More information about the Mono-devel-list mailing list