From: "Morris, Chris" Date: 2002-05-31T22:01:31+09:00 Subject: Threading question Question about Ruby threading. I wrote the following routine trying to create a conflict between one thread deleting an element from the array while another thread is sorting the same array (so that I could properly test my ThreadSafeArray I just posted in another msg...) But it seems that Ruby allows the @a.sort! call to go uninterrupted by other threads. My assumption then is that the granularity never gets smaller than a single line of script. Even though a lot of C code is surely occurring here underneath the sort! call, Ruby allows all of that to occur, holding up the other threads until its done. Is this a correct assumption? def test_ts_array @a = [] (1..1000000).each do @a << rand(100000) end threads = [] (1..3).each do |num| threads << Thread.new(num) { |num| Thread.current["id"] = num (1..10).each do |i| if rand(2) == 1 puts 'delete ' + num.to_s @a.delete_at(@a.length / 2) else puts 'begin sort ' + num.to_s @a.sort! puts 'end sort ' + num.to_s end end } end threads.each { |t| t.join; puts t["id"]} end Chris Morris chris.morris@snelling.com