-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1216 from goblint/priv-atomic
Add some hacky atomic privatizations
- Loading branch information
Showing
30 changed files
with
1,058 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// PARAM: --enable ana.sv-comp.functions | ||
/*----------------------------------------------------------------------------- | ||
* mutex.c - Concurrent program using locking to access a shared variable | ||
*----------------------------------------------------------------------------- | ||
* Author: Frank Schüssele | ||
* Date: 2023-07-11 | ||
*---------------------------------------------------------------------------*/ | ||
#include <pthread.h> | ||
#include <goblint.h> | ||
|
||
extern void __VERIFIER_atomic_begin(); | ||
extern void __VERIFIER_atomic_end(); | ||
|
||
int used; | ||
pthread_mutex_t m; | ||
|
||
void* producer() | ||
{ | ||
while (1) { | ||
pthread_mutex_lock(&m); | ||
used++; | ||
used--; | ||
pthread_mutex_unlock(&m); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
pthread_t tid; | ||
|
||
pthread_mutex_init(&m, 0); | ||
pthread_create(&tid, 0, producer, 0); | ||
|
||
pthread_mutex_lock(&m); | ||
__goblint_check(used == 0); | ||
pthread_mutex_unlock(&m); | ||
|
||
pthread_mutex_destroy(&m); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// PARAM: --enable ana.sv-comp.functions --set ana.activated[+] apron --set ana.relation.privatization mutex-meet-atomic --set ana.base.privatization none | ||
#include <pthread.h> | ||
#include <goblint.h> | ||
|
||
extern void __VERIFIER_atomic_begin(); | ||
extern void __VERIFIER_atomic_end(); | ||
|
||
int myglobal = 5; | ||
|
||
void *t_fun(void *arg) { | ||
__VERIFIER_atomic_begin(); | ||
__goblint_check(myglobal == 5); | ||
myglobal++; | ||
__goblint_check(myglobal == 6); | ||
myglobal--; | ||
__goblint_check(myglobal == 5); | ||
__VERIFIER_atomic_end(); | ||
return NULL; | ||
} | ||
|
||
int main(void) { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
__goblint_check(myglobal == 5); | ||
__VERIFIER_atomic_begin(); | ||
__goblint_check(myglobal == 5); | ||
__VERIFIER_atomic_end(); | ||
pthread_join (id, NULL); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// PARAM: --enable ana.sv-comp.functions --set ana.activated[+] apron --set ana.relation.privatization mutex-meet-atomic --set ana.base.privatization none | ||
#include <pthread.h> | ||
#include <goblint.h> | ||
|
||
int myglobal = 5; | ||
|
||
// atomic by function name prefix | ||
void __VERIFIER_atomic_fun() { | ||
__goblint_check(myglobal == 5); | ||
myglobal++; | ||
__goblint_check(myglobal == 6); | ||
myglobal--; | ||
__goblint_check(myglobal == 5); | ||
} | ||
|
||
void *t_fun(void *arg) { | ||
__VERIFIER_atomic_fun(); | ||
return NULL; | ||
} | ||
|
||
int main(void) { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
__goblint_check(myglobal == 5); | ||
__VERIFIER_atomic_begin(); | ||
__goblint_check(myglobal == 5); | ||
__VERIFIER_atomic_end(); | ||
pthread_join (id, NULL); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// PARAM: --enable ana.sv-comp.functions --set ana.activated[+] apron --set ana.relation.privatization mutex-meet-atomic --set ana.base.privatization none | ||
#include <pthread.h> | ||
#include <goblint.h> | ||
|
||
extern void __VERIFIER_atomic_begin(); | ||
extern void __VERIFIER_atomic_end(); | ||
|
||
int myglobal = 5; | ||
|
||
void *t_fun(void *arg) { | ||
__VERIFIER_atomic_begin(); | ||
__goblint_check(myglobal == 5); // TODO | ||
myglobal++; | ||
__goblint_check(myglobal == 6); // TODO | ||
__VERIFIER_atomic_end(); | ||
return NULL; | ||
} | ||
|
||
int main(void) { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
__goblint_check(myglobal == 5); // UNKNOWN! | ||
__VERIFIER_atomic_begin(); | ||
__goblint_check(myglobal == 5); // UNKNOWN! | ||
__VERIFIER_atomic_end(); | ||
pthread_join (id, NULL); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// PARAM: --enable ana.sv-comp.functions --set ana.activated[+] apron --set ana.relation.privatization mutex-meet-atomic --set ana.base.privatization none | ||
#include <pthread.h> | ||
#include <goblint.h> | ||
|
||
extern void __VERIFIER_atomic_begin(); | ||
extern void __VERIFIER_atomic_end(); | ||
|
||
int myglobal = 0; | ||
int myglobal2 = 0; | ||
int myglobal3 = 0; | ||
|
||
void *t_fun(void *arg) { | ||
__VERIFIER_atomic_begin(); | ||
myglobal2++; | ||
__VERIFIER_atomic_end(); | ||
__VERIFIER_atomic_begin(); | ||
myglobal++; | ||
__VERIFIER_atomic_end(); | ||
return NULL; | ||
} | ||
|
||
void *t2_fun(void *arg) { | ||
__VERIFIER_atomic_begin(); | ||
myglobal3++; | ||
__VERIFIER_atomic_end(); | ||
__VERIFIER_atomic_begin(); | ||
myglobal++; | ||
__VERIFIER_atomic_end(); | ||
return NULL; | ||
} | ||
|
||
int main(void) { | ||
pthread_t id, id2; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
pthread_create(&id2, NULL, t2_fun, NULL); | ||
__goblint_check(myglobal == 2); // UNKNOWN! | ||
__VERIFIER_atomic_begin(); | ||
__goblint_check(myglobal == 2); // UNKNOWN! | ||
__VERIFIER_atomic_end(); | ||
pthread_join (id, NULL); | ||
pthread_join (id2, NULL); | ||
return 0; | ||
} |
Oops, something went wrong.