Jon Skeet said:
And that sounds like a typical threadpool, as I described before, just
with the extra proviso of immediately creating a new thread if one
isn't available.
Yes right som how, but there is a fundemental differnce between those
threads I use to implement coroutines and threadpool threads. Threads in a
thread pool are great for doing some small jobs that terminates. In my case
the job that a thread has to do might be long and extensive. Threads might
(in many cases forced to) give up control to other threads and later have to
continue doing the job, give the control again and so on. There might be
hundreds of threads doing this.
I use threads to implement coroutines (explained in a previous post).When a
thread that is executing a coroutine A my have to be suspend for a while due
to a a call from this coroutine (coroutine A) to give up the control in
favour of another coroutine B. Coroutine B does some work and give the
controll to a coroutine C and so on. Some where in this ocean of threads a
coroutine X may then give the contol back to A. Then A should continue from
its activation point and continue its work. After that and long before its
finished with its task hase to give up control again in favour of another
coroutine R.
This means that every thread which is executing a coroutine should presserve
its execution state. By doing so its alive and "knows" where to continue
when it get the control back.
Let say that I have a simulation system that contains more than 25
coroutines (uses more that 25 threads) and we are using ThreadPool. The task
every coroutine does is very long and takes more than 5 minutes. Let say
that each coroutine does some work and before its finished it gives the
control to the next coroutine. All the first 25 coroutines does this without
a problem. All the 25 threads which are asosiated coroutines are a live.
What happens when coroutine number 25 wants to start/resume the execution of
coroutine number 26? In my openion the simulation system will stop.
Kovan