Skip to content

Commit 16afe85

Browse files
author
Lukas Molzberger
committed
fixed multithreading problem
1 parent 548fea4 commit 16afe85

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/main/java/org/aika/corpus/Document.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,22 @@ public class Queue {
436436
public int compare(Node n1, Node n2) {
437437
int r = Integer.compare(n1.level, n2.level);
438438
if(r != 0) return r;
439-
return Long.compare(n1.queueId, n2.queueId);
439+
440+
ThreadState th1 = n1.getThreadState(threadId, true);
441+
ThreadState th2 = n2.getThreadState(threadId, true);
442+
return Long.compare(th1.queueId, th2.queueId);
440443
}
441444
});
442445

443446
private long queueIdCounter = 0;
444447

445448

446449
public void add(Node n) {
447-
if(!n.isQueued) {
448-
n.isQueued = true;
449-
n.queueId = queueIdCounter++;
450+
ThreadState th = n.getThreadState(threadId, true);
451+
452+
if(!th.isQueued) {
453+
th.isQueued = true;
454+
th.queueId = queueIdCounter++;
450455
queue.add(n);
451456
}
452457
}
@@ -455,12 +460,13 @@ public void add(Node n) {
455460
public void processChanges() {
456461
while(!queue.isEmpty()) {
457462
Node n = queue.pollFirst();
463+
ThreadState th = n.getThreadState(threadId, true);
458464

459-
n.isQueued = false;
465+
th.isQueued = false;
460466
n.processChanges(Document.this);
461467

462468
if(APPLY_DEBUG_OUTPUT) {
463-
log.info("QueueId:" + n.queueId);
469+
log.info("QueueId:" + th.queueId);
464470
log.info(n.toString() + "\n");
465471
log.info("\n" + nodeActivationsToString( true, false));
466472
}

src/main/java/org/aika/lattice/Node.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ public abstract class Node<T extends Node, A extends NodeActivation<T>> extends
8080
// Only the children maps are locked.
8181
public ReadWriteLock lock = new ReadWriteLock();
8282

83-
84-
public boolean isQueued = false;
85-
public long queueId;
86-
8783
public ThreadState<T, A>[] threads;
8884

8985
/**
@@ -101,6 +97,9 @@ public static class ThreadState<T extends Node, A extends NodeActivation<T>> {
10197

10298
public long visited;
10399

100+
public boolean isQueued = false;
101+
public long queueId;
102+
104103
private RidVisited nullRidVisited;
105104
private RidVisited[] ridVisited = new RidVisited[2 * MAX_RELATIVE_RID];
106105

0 commit comments

Comments
 (0)