-
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 thread-const-array-join example from level-ip
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
tests/regression/03-practical/33-thread-const-array-join.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,31 @@ | ||
// Thread pool constant array sequential joining. | ||
// Extracted from concrat/level-ip. | ||
#include <pthread.h> | ||
#include <goblint.h> | ||
|
||
int data = 0; | ||
pthread_mutex_t data_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
void *thread(void *arg) { | ||
pthread_mutex_lock(&data_mutex); | ||
data = __VERIFIER_nondet_int(); // NORACE | ||
pthread_mutex_unlock(&data_mutex); | ||
return NULL; | ||
} | ||
|
||
int main() { | ||
int threads_total = 4; | ||
pthread_t tids[4]; | ||
|
||
// create threads | ||
for (int i = 0; i < threads_total; i++) { | ||
pthread_create(&tids[i], NULL, &thread, NULL); // may fail but doesn't matter | ||
} | ||
|
||
// join threads | ||
for (int i = 0; i < threads_total; i++) { | ||
pthread_join(tids[i], NULL); | ||
} | ||
|
||
return data; // NORACE (all threads joined) | ||
} |