ref: ca5181f70628864f9d4a09e5cbaeaa60801f6729
parent: fb41bc022ada401c69bad8da6802762a7a114803
author: Ori Bernstein <[email protected]>
date: Mon Jan 27 06:42:35 EST 2014
Don't allow for duplicate thread states. If two threads IPs loop around to the same location, then they are duplicate and are going to run in parallel. Kill the second one that reaches the same IP. Slaughter it, like the loser that it is.
--- a/interp.myr
+++ b/interp.myr
@@ -61,7 +61,9 @@
var i, ip
var consumed
var thr
+ var states
+ states = std.mkbitset()
re.runq = mkthread(re, 0)
re.runq.mstart = std.slalloc(re.nmatch)
re.runq.mend = std.slalloc(re.nmatch)
@@ -82,11 +84,16 @@
consumed = step(re, thr, ip)
;;
+ if std.bshas(states, thr.ip)
+ die(re, thr, "there can be only one")
+ ;;
+
if thr.dead
thrfree(re, thr)
elif thr.matched && re.strp == re.str.len
-> thr
elif !thr.matched
+ std.bsput(states, thr.ip)
if re.expired == Zthr
re.expired = thr
;;
@@ -98,6 +105,7 @@
;;
;;
+ std.bsclear(states)
trace(re, thr, "switch\n")
re.runq = re.expired
re.expired = Zthr
--- a/test/regex-basic.myr
+++ b/test/regex-basic.myr
@@ -3,6 +3,35 @@
use "testmatch.use"
const main = {
+ var s : byte[:]
+
+ s = std.strjoin([
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+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