[MacRuby-devel] [MacRuby] #556: Subsequent calls to dispatch apply improperly access incorrect "self"

MacRuby ruby-noreply at macosforge.org
Wed Jan 13 10:51:15 PST 2010


#556: Subsequent calls to dispatch apply improperly access incorrect "self"
---------------------------------------+------------------------------------
 Reporter:  joshua.ballanco@…          |       Owner:  lsansonetti@…        
     Type:  defect                     |      Status:  new                  
 Priority:  blocker                    |   Milestone:                       
Component:  MacRuby                    |    Keywords:  GCD                  
---------------------------------------+------------------------------------
 The following code:
 {{{
 class Array
   def pmap(priority = :default, &block)
     results = []
     results_queue =
 Dispatch::Queue.new("#{results.object_id}_access_queue")
     Dispatch::Queue.concurrent(priority).apply(size) do |idx|
       print "self.object_id #=> #{self.object_id}\n"
       print "self[idx] #=> #{self[idx]}\n"
       result = block[self[idx]]
       print "result #=> #{result}\n"
       results_queue.async do
         results[idx] = result
       end
     end
     results_queue.sync {}
     results
   end
 end

 test_ary = ('a'..'j').to_a
 p test_ary
 print "test_ary.object_id #=> #{test_ary.object_id}\n"
 p test_ary.pmap {|i| i.upcase }

 test_ary = (1..10).to_a
 p test_ary
 print "test_ary.object_id #=> #{test_ary.object_id}\n"
 p test_ary.pmap {|i| i**2 }
 }}}
 ...generates this output:
 {{{
 ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
 test_ary.object_id #=> 8594638688
 self.object_id #=> 8594638688
 self[idx] #=> a
 result #=> A
 self.object_id #=> 8594638688
 self[idx] #=> e
 result #=> E
 self.object_id #=> 8594638688
 self[idx] #=> f
 result #=> F
 self.object_id #=> 8594638688
 self[idx] #=> g
 result #=> G
 self.object_id #=> 8594638688
 self[idx] #=> h
 result #=> H
 self.object_id #=> 8594638688
 self[idx] #=> i
 self.object_id #=> 8594638688
 result #=> I
 self[idx] #=> b
 self.object_id #=> 8594638688
 self[idx] #=> j
 result #=> J
 result #=> B
 self.object_id #=> 8594638688
 self[idx] #=> c
 result #=> C
 self.object_id #=> 8594638688
 self[idx] #=> d
 result #=> D
 ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 test_ary.object_id #=> 8591101024
 self.object_id #=> 8594638688
 self[idx] #=> a
 result #=> A
 self.object_id #=> 8591101024
 self.object_id #=> 8591101024
 self[idx] #=> 2
 self[idx] #=> 3
 result #=> 9
 self.object_id #=> 8594638688
 result #=> 4
 self.object_id #=> 8591101024
 self[idx] #=> f
 self.object_id #=> 8591101024
 self[idx] #=> 4
 self.object_id #=> 8591101024
 self[idx] #=> 5
 result #=> F
 self[idx] #=> 8
 self.object_id #=> 8591101024
 result #=> 16
 self.object_id #=> 8591101024
 self.object_id #=> 8591101024
 result #=> 25
 result #=> 64
 self[idx] #=> 9
 self[idx] #=> 10
 self[idx] #=> 7
 result #=> 81
 result #=> 100
 result #=> 49
 [nil, 4, 9, 16, 25, nil, 49, 64, 81, 100]
 }}}

 Notice that, in the second call to #pmap, some of the iterations of
 Dispatch::Queue#apply evaluate "self" as the "self" from the first call to
 #pmap

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/556>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list