Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
threads demo from pickaxe book - newbie question
Christopher Rose
4/23/2007 4:46:00 PM
All,
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 -
Chris
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
super
end
def tick
synchronize do
@count += 1
end
end
end
c = Counter.new
t1 = Thread.new { 100_000.times { c.tick } }
t2 = Thread.new { 100_000.times { c.tick } }
t1.join ; t2.join
c.count
--
Posted via
http://www.ruby-...
.
2 Answers
Amos King
4/23/2007 5:24:00 PM
0
The super call is calling the initialize function in The base class,
in this case Monitor
On 4/23/07, Christopher Rose <chrisrose.chrisrose@gmail.com> wrote:
> All,
>
> 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 -
>
> Chris
>
> 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
> super
> end
> def tick
> synchronize do
> @count += 1
> end
> end
> end
>
> c = Counter.new
> t1 = Thread.new { 100_000.times { c.tick } }
> t2 = Thread.new { 100_000.times { c.tick } }
>
> t1.join ; t2.join
>
> c.count
>
> --
> Posted via
http://www.ruby-...
.
>
>
--
Amos King
Ramped Media
USPS
Programmer/Analyst
St. Louis, MO
Looking for something to do? Visit ImThere.com
Amos King
4/23/2007 5:47:00 PM
0
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 = Thread.new { 1_000.times { puts 'thread 1' } }
t2 = Thread.new { 1_000.times { puts 'thread 2' } }
t3 = Thread.new { 1_000.times { puts 'thread 3' } }
t4= Thread.new { 1_000.times { puts 'thread 4' } }
On 4/23/07, Amos King <amos.l.king@gmail.com> wrote:
> The super call is calling the initialize function in The base class,
> in this case Monitor
>
> On 4/23/07, Christopher Rose <chrisrose.chrisrose@gmail.com> wrote:
> > All,
> >
> > 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 -
> >
> > Chris
> >
> > 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
> > super
> > end
> > def tick
> > synchronize do
> > @count += 1
> > end
> > end
> > end
> >
> > c = Counter.new
> > t1 = Thread.new { 100_000.times { c.tick } }
> > t2 = Thread.new { 100_000.times { c.tick } }
> >
> > t1.join ; t2.join
> >
> > c.count
> >
> > --
> > Posted via
http://www.ruby-...
.
> >
> >
>
>
> --
> Amos King
> Ramped Media
> USPS
> Programmer/Analyst
> St. Louis, MO
> Looking for something to do? Visit ImThere.com
>
>
--
Amos King
Ramped Media
USPS
Programmer/Analyst
St. Louis, MO
Looking for something to do? Visit ImThere.com
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
threads demo from pickaxe book - newbie question
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password