Race Condition
- Tags
- comp-sci
Is a bug in multi-threaded programs where the outcome of some code is determined by the processor. I.E. It's inconsistent (non-deterministic) from one run to the next.
void *thread_main(void *p) {
int *p_int = (int*) p;
int x = *p_int;
x += x;
*p_int = x;
return NULL;
}
int main() {
int data = 1;
pthread_t one, two;
pthread_create(&one, NULL, thread_main, &data);
pthread_create(&two, NULL, thread_main, &data);
pthread_join(one, NULL);
pthread_join(two, NULL);
printf("%d\n", data);
return 0;
}