Ivan Denisov wrote:
This procedure is executing without interrupts. Why you think, that this is speeding up garbage collection?
Anyway you said, that the main benefit of this realization is the consistency, but you sacrificed it for possible speeding up of garbage collection.
It allows to remove a coroutine from the list of coroutines as early as possible, i.e. when the coroutine returns (or traps).
At that time the coroutine is still running but the stack is no longer needed for garbage collection.
A coroutine stack may lead to a complete heap scan, which is a very expensive operation in the garbage collector.
This has nothing to do with interrupts. The garbage collector may be called later.
Ivan Denisov wrote:
Also I can not understand why mu CPU is 7% load with Primes example... Why it is not 100% load? Is it possible to add simple balancer?
Should the background task effectively use the time with Sleep(0) or not?
A Task transfers to main periodically in order not to block the user interface.
The Windows idle period then limits the CPU utilization, I guess.
If you run in Server Mode it should be higher. Also if you start more than one task.
In any case, there is only one CPU being used. So if you have a multicore system
you must look at the CPU utilization per CPU.
There is only a very simple mechanism behind Task. But if you want to
add more features it gets complicated quickly.
And one of the core problems is the precision of the Windows tick count, which is very
coarse grained. In addition, it will never behave like a multi-threaded system
using a preemptive scheduler. There are limits and trade-offs, even in Co_.
The current implementation is the simplest that delivers useful results, I believe.
Anything beyond that is left to applications (or future refinements).
- Josef