Updated 2017-11-10 23:44:34 by MHo

tpool — Part of the Tcl threading extension implementing pools of worker threads

MHo 2017-07-31 There's something that I don't understand:

Why ist the runtime of
set pool1 [tpool::create -minworkers 10 -maxworkers 20 -idletime 10]
for {set i 1} {$i <= 20} {incr i} {
    lappend jobs [tpool::post $pool1 {after 10000}
}
while {[llength $jobs]} {
      set ready [tpool::wait $pool1 $jobs jobs]
}

double the time of
set pool1 [tpool::create -minworkers 20 -maxworkers 20 -idletime 10]
for {set i 1} {$i <= 20} {incr i} {
    lappend jobs [tpool::post $pool1 {after 10000}
}
while {[llength $jobs]} {
      set ready [tpool::wait $pool1 $jobs jobs]
}

The first call runs ~20,xs, the second one, as expected, ~10,xs.

The documentation states, the only difference is the time at which the workers are created - beforehand, or "on demand" when a post is done. As there are enough -maxworkers defined, what is limiting the operation then...?

I also asked this on that page: Ask, and it shall be given # 12

I've looked at several examples that I've found here and there, and it seems that almost everyone sets -min == -max..... There must be something misterious around this values. I can also specify -minworkers 40 -maxworkers 20, no problem. 40 Workers are created.... Ok, this last fact becomes clear after looking at the c-source:
    if (minw > maxw) {
        maxw = minw;
    }

Even more mystery....it works as expected with this little variation:
set pool1 [tpool::create -minworkers 1 -idletime 10]
for {set i 1} {$i <= 20} {incr i} {
    lappend jobs [tpool::post $pool1 {after 10000}
    puts $jobs; # <--------- mystery
}
while {[llength $jobs]} {
      set ready [tpool::wait $pool1 $jobs jobs]
}

So, I think the answer to myself is for now:

Posting jobs one after another without doing something between each iteration blocks the start of new threads. Btw, it's not clear, what something exactly is, and why it helps....