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 It seems to produce the error for ring_size >= 206 - 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. [SL] It does return 498 for N = 1000. I can create up to ~800 threads. I guess to run this script in the same shell multiple time you have to release some threads. ====== 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 ====== ---- !!!!!! %| [Category Performance] |% !!!!!!