From: Kero van Gelder Date: 2002-08-28T07:22:43+09:00 Subject: Re: BUG: threads and ruby/tk > Here is the code: [snippits] > -------------------------------- > $count=TkVariable.new "start" > t=Thread.new { > loop { > $count.value="blah" > } > } > Tk.mainloop > -------------------------------- Classic problem. You set Tk stuff from a second thread, where the mainloop expects to be the only one doing so. In other words, race conditions. The result: totally weird behaviour. I would be curious whether other toolkits suffer from this, too. The solution is called TkAfter and I should probably write a chapter about it in my tutorial. Example I got from Hidetoshi Nagai: ------------------------------------------------------------- require 'tk' tlist = [500, 2000] TkAfter.new(proc{t = tlist.shift; tlist.push(t); t}, -1, proc{p 1}, proc{p 2}).start Tk.mainloop ------------------------------------------------------------- This script will print "1" after waiting 0.5s at first, and "2" after waiting 2.0s from the end of printing "1". After that, it will repeat same process. Hope this helps, Kero. +--- Kero ------------------------------ kero@chello.nl ---+ | Don't split your mentality without thinking twice | | Proud like a God -- Guano Apes | +--- M38c ---------- http://httpd.chello.nl/k.vangelder ---+