threads, Hash#delete_if, and ruby segfaults.

N

Neil Spring

should the following code cause the ruby interpreter to segfault? If
so, resolv.rb should have a mutex guard @senders. If not, st_foreach
should avoid the race when independent threads delete adjacent elements
from the same linked list.

#!/usr/bin/ruby

desired_length = 10000

hash = Hash.new
threads = (0..4).map { |i|
Thread.new {
while true
hash.delete_if { |k,v| Kernel.rand > 0.5 }
while hash.length < desired_length
hash[Kernel.rand(desired_length * 10)] = 12
end
end
}
}

(I submitted a really clunky version of this as ruby bug 1326 with not
nearly so simple a test case, but can't figure out how to follow up to
the message).

thanks,
-neil
 
Y

Yukihiro Matsumoto

Hi,

In message "threads, Hash#delete_if, and ruby segfaults."

|should the following code cause the ruby interpreter to segfault? If
|so, resolv.rb should have a mutex guard @senders. If not, st_foreach
|should avoid the race when independent threads delete adjacent elements
|from the same linked list.

It is fixed in the latest snapshot.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top