-
Notifications
You must be signed in to change notification settings - Fork 76
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 #1607 from goblint/pthread_self
Add `pthread_self` support
- Loading branch information
Showing
7 changed files
with
100 additions
and
3 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
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,29 @@ | ||
//PARAM: --set ana.activated[+] threadJoins | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
|
||
pthread_t mainid; | ||
|
||
int g = 10; | ||
|
||
void *t_fun(void *arg) { | ||
int r = pthread_join(mainid, NULL); // TSan doesn't like this... | ||
printf("j: %d\n", r); | ||
g++; // NORACE | ||
printf("t_fun: %d\n", g); | ||
return NULL; | ||
} | ||
|
||
|
||
int main(void) { | ||
mainid = pthread_self(); | ||
|
||
pthread_t id2; | ||
pthread_create(&id2, NULL, t_fun, NULL); | ||
|
||
g++; // NORACE | ||
printf("main: %d\n", g); | ||
|
||
pthread_exit(NULL); // exit main thread but keep id2 alive, otherwise main returning kills id2 | ||
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,29 @@ | ||
//PARAM: --set ana.activated[+] threadJoins --set ana.thread.domain plain | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
|
||
pthread_t mainid; | ||
|
||
int g = 10; | ||
|
||
void *t_fun(void *arg) { | ||
int r = pthread_join(mainid, NULL); // TSan doesn't like this... | ||
printf("j: %d\n", r); | ||
g++; // RACE (imprecise by plain thread IDs) | ||
printf("t_fun: %d\n", g); | ||
return NULL; | ||
} | ||
|
||
|
||
int main(void) { | ||
mainid = pthread_self(); | ||
|
||
pthread_t id2; | ||
pthread_create(&id2, NULL, t_fun, NULL); | ||
|
||
g++; // NORACE | ||
printf("main: %d\n", g); | ||
|
||
pthread_exit(NULL); // exit main thread but keep id2 alive, otherwise main returning kills id2 | ||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/regression/51-threadjoins/11-join-main-plain-no-node.c
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,29 @@ | ||
//PARAM: --set ana.activated[+] threadJoins --set ana.thread.domain plain --disable ana.thread.include-node | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
|
||
pthread_t mainid; | ||
|
||
int g = 10; | ||
|
||
void *t_fun(void *arg) { | ||
int r = pthread_join(mainid, NULL); // TSan doesn't like this... | ||
printf("j: %d\n", r); | ||
g++; // RACE (imprecise by plain thread IDs) | ||
printf("t_fun: %d\n", g); | ||
return NULL; | ||
} | ||
|
||
|
||
int main(void) { | ||
mainid = pthread_self(); | ||
|
||
pthread_t id2; | ||
pthread_create(&id2, NULL, t_fun, NULL); | ||
|
||
g++; // RACE (imprecise by plain thread IDs not knowing if main is actual main or spawned by program) | ||
printf("main: %d\n", g); | ||
|
||
pthread_exit(NULL); // exit main thread but keep id2 alive, otherwise main returning kills id2 | ||
return 0; | ||
} |