Forum: Ruby threads demo from pickaxe book - newbie question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
441944df04d357c3b1772ea7c724c70f?d=identicon&s=25 Christopher Rose (chrisrose67)
on 2007-04-23 18:46

Please forgive a newbie question - I have tried searching for errata on
the Pickaxe book (2nd ed) but not found an answer.  I am running Ruby
1.8.2 on WinXP.  I type in, or source from file, the example - from pg.
143, copied below - into the interactive ruby prompt in the fxri tool.
I get to the line

t1.join ; t2.join

and the tool hangs.  Is this expected?  Is there some better way(s) to
debug thread-related issues?  Thanks for any advice -


P.S. Could someone please explain the purpose of the 'super' command in
this script?  Thx -

-----------------------<begin example pg. 143>----------------------

# with my current version of fxri, this hangs
 require 'monitor'
 class Counter < Monitor
  attr_reader :count
  def initialize
    @count = 0
  def tick
    synchronize do
      @count += 1

 c =
 t1 = { 100_000.times { c.tick } }
 t2 = { 100_000.times { c.tick } }

 t1.join ; t2.join

F04aeb28129f653b207e8b5d92706096?d=identicon&s=25 Amos King (Guest)
on 2007-04-23 19:24
(Received via mailing list)
The super call is calling the initialize function in The base class,
in this case Monitor
F04aeb28129f653b207e8b5d92706096?d=identicon&s=25 Amos King (Guest)
on 2007-04-23 19:49
(Received via mailing list)
I ran your script as a file and not from irb.  works just fine, but
really doesn't show the threads working that well.  You should just
try something like

t1 = { 1_000.times { puts 'thread 1' } }
t2 = { 1_000.times { puts 'thread 2' } }
t3 = { 1_000.times { puts 'thread 3' } }
t4= { 1_000.times { puts 'thread 4' } }
This topic is locked and can not be replied to.