Skip to content

Instantly share code, notes, and snippets.

@TeWu
Created October 14, 2011 00:14
Show Gist options
  • Save TeWu/1285894 to your computer and use it in GitHub Desktop.
Save TeWu/1285894 to your computer and use it in GitHub Desktop.
naive multithreaded catastrophic backtracking
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