Brendan Ang

Search

Search IconIcon to open search

Software Model Checking

Last updated Apr 28, 2023 Edit Source

# Software Model Checking

Model Checking is traditionally applied to protocols/algorithms and specifications. Software model checking tries to find failures in well, software.

Software model checking tools can backtrack and explore different thread schedules for a concurrent program and in the process find all possible failures.

# Java Pathfinder

Java Pathfinder is a software model checker for Java bytecode.

An example with the Dining Philosophers problem:

Thread Name/ Transmainthread 1thread 2thread 3thread 4thread 5
0create Forks in loop
1-12create Philosophers and launch threads
13-14obtain lock 1c4; try to obtain 1c5
15-16obtain lock 1c5; try to obtain 1c6
17-18obtain lock 1c6; try to obtain 1c7
19-20obtain lock 1c7; try to obtain 1c8
21-22obtain lock 1c8; try to obtain 1c4

300 %% 🖋 Edit in Excalidraw, and the dark exported image%%

Thread Name/ Transmainthread 1thread 2
1-3creates workers and starts 2 threads
4obtains lock on Queue
5puts data into Queue
6tries to remove data but enters wait()
7tries to put data but queue is full so wait()
Thread Name/ Transmainthread 1thread 2thread 3thread 4
0-44starts 2 producers and 2 consumer threads
45tries to put data; obtains lock
46-51tries to remove data; wait()
52-53tries to put data
54-56tries to remove data; wait()
57puts data
58-59notify()
60obtains lock on queue; tries to put data; wait()

In QueueTest, there are only 2 workers, each having to put data first before removing data. If the queue is full or there is no data for the respective operations, they wait. The signal from notify() can only be lost if 1 worker finishes execution before the 2nd worker begins. However, in that case, the queue would be empty and the 2nd worker would not need to wait() in the first place.