Version 7 of thread-ring benchmark

Updated 2008-06-05 06:54:02 by jmn

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.

Any ideas as to what limit I'm hitting?

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

jmn Tcl 8.5.2b1 - Vista x64 - core2 2.4Ghz 4G ram

- also, due to the above error, I haven't verified that the code below produces the right result. If anyone else runs it sucessfully, please make a note here as to whether it produces the expected result for N = 1000, of 498; thanks.

 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