Created
October 14, 2011 00:14
-
-
Save TeWu/1285894 to your computer and use it in GitHub Desktop.
naive multithreaded catastrophic backtracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = /\A(aa|aab?)+\Z/ | |
@counter = 0 | |
s = "" | |
t = [] | |
64.times { t << Thread.fork { puts "start" }; t.last.join } | |
while s.length < 200 | |
i = s.length % t.size | |
t[i].join | |
t[i] = Thread.fork(s.dup) do |s| | |
if s =~ p | |
puts "+ #{@counter += 1}" | |
else | |
puts " #{@counter}" | |
end | |
end | |
s += "a" | |
end | |
puts "\nFINAL RESULT: #{counter}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment