Skip to content

Commit

Permalink
Added synchronization to fix NPE bug in MessageHandler (#72)
Browse files Browse the repository at this point in the history
Tested by running several of the tests in the jkind testing
directory looking for possible deadlocks and performance changes.
There is a slight performance hit using synchronized for message
passing (a few seconds, depending on the problem), and no
deadlocks occurred.
  • Loading branch information
mww-aws authored Aug 29, 2022
1 parent 3d49475 commit e21d4f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.text.SimpleDateFormat;

def jkind_version_base = '4.5.1'
def jkind_version_base = '4.5.2'

def buildTime() {
def df = new SimpleDateFormat("yyyyMMddHHmm");
Expand Down
16 changes: 14 additions & 2 deletions jkind/src/jkind/engines/messages/MessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@
public abstract class MessageHandler {
private BlockingQueue<Message> incoming = new LinkedBlockingQueue<>();

public void receiveMessage(Message message) {
// MWW, 8/27/2022
// receiveMessage and stopReceivingMessages run on different threads,
// leading to occasional NPE exceptions due to race conditions when solver
// is completing analyses.
//
// NPEs happen when incoming is checked for null, but then receiveMessage
// thread is interrupted and incoming is set to null by stopReceivingMessages
// prior to incoming.add(message).
//
// Note that other protected functions do not need to be
// synchronized because they are called on the same thread
// as stopReceivingMessages.
public synchronized void receiveMessage(Message message) {
if (incoming != null) {
incoming.add(message);
}
}

protected void stopReceivingMessages() {
protected synchronized void stopReceivingMessages() {
incoming = null;
}

Expand Down

0 comments on commit e21d4f2

Please sign in to comment.