Skip to content

Commit 1e73fc3

Browse files
Fix parallel execution of termination runs
1 parent 52fa47c commit 1e73fc3

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

2ls.inc

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,65 @@
1-
# tool
1+
# tool
22

33
TOOL_BINARY=./2ls-binary
44
TOOL_NAME=2LS
55

66
# function to run the tool
77

8-
run()
8+
run()
99
{
1010
# add property-specific options
1111
if [[ "$PROP" == "termination" ]]; then
12-
PROPERTY="$PROPERTY --termination --competition-mode"
12+
PROPERTY1="$PROPERTY --termination --competition-mode"
1313
PROPERTY2="$PROPERTY --nontermination --competition-mode"
14-
14+
1515
# run the termination and nontermination analysis in parallel
16-
$TOOL_BINARY --graphml-witness $LOG.witness $BIT_WIDTH $PROPERTY \
17-
--function $ENTRY $BM >> $LOG.ok 2>&1 &
16+
$TOOL_BINARY --graphml-witness $LOG.witness $BIT_WIDTH $PROPERTY1 \
17+
--function $ENTRY $BM >> $LOG.ok1 2>&1 &
18+
PID1="$!"
1819
$TOOL_BINARY --graphml-witness $LOG.witness $BIT_WIDTH $PROPERTY2 \
19-
--function $ENTRY $BM >> $LOG.ok 2>&1 &
20-
wait -n
21-
20+
--function $ENTRY $BM >> $LOG.ok2 2>&1 &
21+
PID2="$!"
22+
# this might not work in all environments
23+
wait -n &> /dev/null
24+
2225
# store the exit code of the first process that is finished
2326
EC=$?
24-
25-
# if the result of termination analysis is unknown,
26-
# wait for the most recently executed background process,
27-
# which is nontermination analysis
28-
if [$EC -eq 5]; then
29-
wait $!
27+
28+
# find out which one has finished
29+
for pid in $PID1 $PID2
30+
do
31+
if ! ps -p $pid &> /dev/null; then
32+
EXITED=$pid
33+
break
34+
fi
35+
done
36+
37+
# if the result of the first exiting analysis is inconclusive
38+
# then wait for the other analysis to finish
39+
if [ $EC -eq 5 ]; then
40+
wait -n &> /dev/null
3041
EC=$?
42+
if [[ "$EXITED" == "$PID1" ]]; then
43+
mv $LOG.ok2 $LOG.ok
44+
else
45+
mv $LOG.ok1 $LOG.ok
46+
fi
47+
else # we have a conclusive result, kill the other process
48+
if [[ "$EXITED" == "$PID1" ]]; then
49+
kill -9 $PID2 &> /dev/null
50+
mv $LOG.ok1 $LOG.ok
51+
else
52+
kill -9 $PID1 &> /dev/null
53+
mv $LOG.ok2 $LOG.ok
54+
fi
3155
fi
3256
else
3357
PROPERTY="$PROPERTY --k-induction --competition-mode"
34-
58+
3559
# run the tool
3660
$TOOL_BINARY --graphml-witness $LOG.witness $BIT_WIDTH $PROPERTY \
3761
--function $ENTRY $BM >> $LOG.ok 2>&1
38-
62+
3963
# store the exit code
4064
EC=$?
4165
fi

0 commit comments

Comments
 (0)