-
Notifications
You must be signed in to change notification settings - Fork 0
/
case_distinction_with_ghosts.c
71 lines (58 loc) · 2.04 KB
/
case_distinction_with_ghosts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*-----------------------------------------------------------------------------
* case_distinction_with_ghosts.c - Annotated concurrent program with ghost
* variables for witness validation that
* non-deterministically increments the value
* of a shared variable
*-----------------------------------------------------------------------------
* Author: Frank Schüssele
* Date: 2023-07-12
*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <pthread.h>
/*-----------------------------------------------------------------------------
* Ultimate-specific declarations
*---------------------------------------------------------------------------*/
typedef unsigned long int pthread_t;
/*-----------------------------------------------------------------------------
* SV-Comp-specific function declarations
*---------------------------------------------------------------------------*/
extern int __VERIFIER_nondet_int();
extern void __VERIFIER_atomic_begin();
extern void __VERIFIER_atomic_end();
extern void reach_error();
/*-----------------------------------------------------------------------------
* Declarations, functions and entry point of concurrent program
*---------------------------------------------------------------------------*/
int x;
int g = 0;
void* inc()
{
int n = __VERIFIER_nondet_int();
while (1) {
__VERIFIER_atomic_begin();
int cond = x < n;
__VERIFIER_atomic_end();
if (!cond) break;
__VERIFIER_atomic_begin();
x++;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
int cond2 = g != 1 || x >= 42;
__VERIFIER_atomic_end();
if (!cond2) reach_error();
}
return 0;
}
int main()
{
pthread_t tid;
pthread_create(&tid, 0, inc, 0);
__VERIFIER_atomic_begin();
g = 1; x = 42;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
int cond = x >= 42;
__VERIFIER_atomic_end();
if (!cond) reach_error();
return 0;
}