Created
July 19, 2019 10:42
-
-
Save jsvd/a3556820266838c53dff0ed4466dc214 to your computer and use it in GitHub Desktop.
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
# this terminates quickly in mri but hangs in jruby | |
def regex_dos | |
"foo========:bar baz================================================bingo".scan(/(?:=+=+)+:/) | |
end | |
t = Thread.new { regex_dos(); puts "done" } | |
puts t.status | |
t.kill | |
puts t.status | |
t.join | |
puts "joined" |
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
posstr = "NRNRNNVVNRNNNNNNPUNNNNPUNRNNNNNNNNNNNNNRNNNNNRNNNRNNNNJJNNCCNNNRNNVVNNNNNRNNNNNRNNNNNRNNNNNRNNNRNNNNNNNNNNCCNNNNNNNNNNNNNNNRNNNNNNPUNNNNPUNNNNNNNRNNNNNNNRNNNNNNNNNNNNNNNNNNNNNNNNNRNNNNNNNNVVNNNNNNNNNNNNNNNNNNNNNRNNNNNNNNNRNNNNNNPUNNNNPUNRNNNNNNNNCCNNJJNN" | |
re = /((?:(?:(?:JJ|VA)(?:DEC)?)*|AS)?(?:(?:NN|NR|NT)+(?:PU|CC|PP)?)+)$/ | |
re_thread = Thread.new { posstr.scan(re) } | |
java_thread = JRuby.reference(re_thread).native_thread | |
# timeout after 1 seconds | |
sleep 1 | |
java_thread.interrupt | |
sleep 1 | |
# wait for thread to die | |
re_thread.join | |
puts "successfully interrupted thread!" |
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
require 'timeout' | |
posstr = "NRNRNNVVNRNNNNNNPUNNNNPUNRNNNNNNNNNNNNNRNNNNNRNNNRNNNNJJNNCCNNNRNNVVNNNNNRNNNNNRNNNNNRNNNNNRNNNRNNNNNNNNNNCCNNNNNNNNNNNNNNNRNNNNNNPUNNNNPUNNNNNNNRNNNNNNNRNNNNNNNNNNNNNNNNNNNNNNNNNRNNNNNNNNVVNNNNNNNNNNNNNNNNNNNNNRNNNNNNNNNRNNNNNNPUNNNNPUNRNNNNNNNNCCNNJJNN" | |
re = /((?:(?:(?:JJ|VA)(?:DEC)?)*|AS)?(?:(?:NN|NR|NT)+(?:PU|CC|PP)?)+)$/ | |
status = Timeout::timeout(5) { posstr.scan(re) } | |
puts status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment