-
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 #1343 from goblint/issue_1287
Refine Points-To set on locking a mutex
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include<pthread.h> | ||
|
||
pthread_mutex_t m1; | ||
pthread_mutex_t m2; | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int top; | ||
pthread_mutex_t* ptr; | ||
ptr = &m1; | ||
|
||
if(top) { | ||
ptr = &m2; | ||
} | ||
|
||
pthread_mutex_lock(ptr); | ||
pthread_mutex_unlock(ptr); //NOWARN | ||
|
||
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,37 @@ | ||
#include<pthread.h> | ||
|
||
pthread_mutex_t m1; | ||
pthread_mutex_t m2; | ||
pthread_mutex_t* ptr; | ||
|
||
void other() { | ||
int top; | ||
ptr = &m2; | ||
|
||
if(top) { | ||
ptr = &m1; | ||
} | ||
} | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
int top; | ||
|
||
ptr = &m1; | ||
|
||
if(top) { | ||
ptr = &m2; | ||
} | ||
|
||
pthread_t mischievous; | ||
pthread_create(&mischievous, NULL, other, NULL); | ||
|
||
|
||
pthread_mutex_lock(ptr); | ||
|
||
// This has to produce a warning, as the other thread may have changed what | ||
// ptr points to such that it's not the same mutex being unlocked here. | ||
pthread_mutex_unlock(ptr); //WARN | ||
|
||
return 0; | ||
} |