Ran into this issue trying to verify a program, I've written up a small MWE below.
The reader thread should be picking up its own store to f.wait, but the tool reports a read from uninitialised memory.
If run with -cache-instructions, it gives an internal error.
Also, the execution time estimate is shown as "-nans".
Replacing the local declaration with a globally declared variable (but not adding any additional writes) fixes the issue.
Replacing the struct with a single atomic int also appears to fix it.
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdatomic.h>
#include <genmc.h>
struct flag {
_Atomic unsigned int wait ;
};
#define FLAGS 1
_Atomic (struct flag*) flags[FLAGS];
pthread_t writer;
pthread_t reader;
void* read(void* i) {
struct flag f;
_Atomic struct flag* p = &f;
atomic_store_explicit(&flags[(int)i], p, memory_order_release);
atomic_store_explicit(&f.wait, 1, memory_order_release);
while (atomic_load_explicit(&f.wait, memory_order_relaxed));
pthread_join(&writer, NULL);
}
void* write(void* p) {
for(int i = 0; i < FLAGS; i++) {
struct flag* f;
do {f = atomic_load_explicit(&flags[i], memory_order_acquire);}
while (f == NULL);
atomic_store_explicit(&f->wait, 0, memory_order_relaxed);
}
}
int main() {
pthread_create(&writer, NULL, &write, NULL);
pthread_create(&reader, NULL, &read, (void*)0);
pthread_join(reader, NULL);
pthread_join(writer, NULL);
}
Ran into this issue trying to verify a program, I've written up a small MWE below.
The reader thread should be picking up its own store to f.wait, but the tool reports a read from uninitialised memory.
If run with -cache-instructions, it gives an internal error.
Also, the execution time estimate is shown as "-nans".
Replacing the local declaration with a globally declared variable (but not adding any additional writes) fixes the issue.
Replacing the struct with a single atomic int also appears to fix it.