-
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.
Extract symbolic-thread-struct-in-array example from ProcDump-for-Linux
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
tests/regression/03-practical/43-symbolic-thread-struct-in-array.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,39 @@ | ||
// Per-thread structs in array passed via argument. | ||
// Extracted from concrat/ProcDump-for-Linux. | ||
#include <stdlib.h> | ||
#include <pthread.h> | ||
#include <goblint.h> | ||
extern int __VERIFIER_nondet_int(); | ||
|
||
struct thread { | ||
int data; | ||
}; | ||
|
||
void *thread(void *arg) { | ||
struct thread *t = arg; | ||
t->data = __VERIFIER_nondet_int(); // NORACE | ||
return NULL; | ||
} | ||
|
||
int main() { | ||
int threads_total = __VERIFIER_nondet_int(); | ||
__goblint_assume(threads_total >= 0); | ||
|
||
pthread_t *tids = malloc(threads_total * sizeof(pthread_t)); | ||
struct thread *ts = malloc(threads_total * sizeof(struct thread)); | ||
|
||
// create threads | ||
for (int i = 0; i < threads_total; i++) { | ||
pthread_create(&tids[i], NULL, &thread, &ts[i]); // may fail but doesn't matter | ||
} | ||
|
||
// join threads | ||
for (int i = 0; i < threads_total; i++) { | ||
pthread_join(tids[i], NULL); | ||
} | ||
|
||
free(tids); | ||
free(ts); | ||
|
||
return 0; | ||
} |