-
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 #1082 from goblint/thread-unsafe-funs
Detect calls of thread-unsafe functions as races
- Loading branch information
Showing
7 changed files
with
82 additions
and
15 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
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,22 @@ | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
|
||
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; | ||
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *t_fun(void *arg) { | ||
pthread_mutex_lock(&mutex1); | ||
rand(); // RACE! | ||
pthread_mutex_unlock(&mutex1); | ||
return NULL; | ||
} | ||
|
||
int main(void) { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
pthread_mutex_lock(&mutex2); | ||
rand(); // RACE! | ||
pthread_mutex_unlock(&mutex2); | ||
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,21 @@ | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
|
||
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *t_fun(void *arg) { | ||
pthread_mutex_lock(&mutex1); | ||
rand(); // NORACE | ||
pthread_mutex_unlock(&mutex1); | ||
return NULL; | ||
} | ||
|
||
int main(void) { | ||
pthread_t id; | ||
pthread_create(&id, NULL, t_fun, NULL); | ||
pthread_mutex_lock(&mutex1); | ||
rand(); // NORACE | ||
pthread_mutex_unlock(&mutex1); | ||
pthread_join (id, NULL); | ||
return 0; | ||
} |