Skip to content

Commit

Permalink
Merge pull request #1230 from goblint/issue_1223
Browse files Browse the repository at this point in the history
`threadAnalysis`: Only add to set of must-joined threads if argument to `pthread_join` evaluates to a singleton
  • Loading branch information
michael-schwarz authored Nov 2, 2023
2 parents c42ec6b + 1d55756 commit 808e91d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/analyses/threadAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ struct
s
in
match TS.elements (ctx.ask (Queries.EvalThread id)) with
| threads -> List.fold_left join_thread ctx.local threads
| [t] -> join_thread ctx.local t (* single thread *)
| _ -> ctx.local (* if several possible threads are may-joined, none are must-joined *)
| exception SetDomain.Unsupported _ -> ctx.local)
| _ -> ctx.local

Expand Down
25 changes: 25 additions & 0 deletions tests/regression/10-synch/28-join-array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// PARAM: --set ana.activated[+] thread
#include <pthread.h>

int data = 0;
pthread_mutex_t data_mutex;

void *thread(void *arg) {
pthread_mutex_lock(&data_mutex);
data = 3; // RACE!
pthread_mutex_unlock(&data_mutex);
return NULL;
}

int main() {
pthread_t tids[2];

pthread_create(&tids[0], NULL, &thread, NULL);
pthread_create(&tids[1], NULL, &thread, NULL);

pthread_join(tids[0], NULL);

data = 1; //RACE!

return 1;
}

0 comments on commit 808e91d

Please sign in to comment.