I try to write a program for physical simulations. I use two threads, one for the calculations and one for the gui. To exchange data between them I use a struct
struct sim_data {
int running;
int steps;
int progress;
...
};
and include it in the different threads
void *sim(void *args) {
struct sim_data *my_data;
my_data=(struct sim_data *)args;
...
}
When setting a value by
my_data->progress=1000;
the data is available in the same thread but not reliably in the second thread. I would guess a chance of 10% when starting the program to read a different value in the second thread then writing in the first one. While the data is written in a loop, I don't think it's a timing problem.
I think this is very strange. Any guess what's going wrong?