Version 3 of thread-ring benchmark

Updated 2008-06-04 20:59:00 by escargo

See http://shootout.alioth.debian.org/gp4/benchmark.php?test=threadring&lang=all


jmn I tried the following, but it errors out with "can't create a new thread" - even though my system appears to have plenty of free memory.

escargo 4 Jun 2008 - Well, how about telling us what version of Tcl and system you are using, plus a description of its hardware resourced?

Any ideas as to what limit I'm hitting?

 set ring_size 503
 set N 1000
 package require Thread
 proc done {} {
         set ::done 1
 }
 set script {
         proc accept {t} {
                 if {$t == 0} {
                         puts stdout "%i%"
                         thread::send -async %m% done
                         return
                 }
                 thread::send -async %n% [list accept [expr {$t - 1}] ]
         }
         %do%
 }
 set t1 [set tnext [thread::create {thread::wait}]]
 for {set i $ring_size} {$i >1} {incr i -1} {
          set tnext [thread::create [string map [list %m% [thread::id] %i% $i %n% $tnext %do% "thread::wait"] $script]]
 }
 #close the ring
 set script [string map [list %m% [thread::id] %i% 1 %n% $tnext %do% [list accept $N]] $script]
 thread::send -async $t1 $script
 vwait ::done