#include <stdio.h>
#include <pthread.h>

#define THREAD_COUNT 4
#define REPEATS 100000

long long total = 0;

void *count(void *argument) {
    (void)argument;  /* This worker does not need an ID. */
    /* Intentionally incorrect: concurrent updates cause a data race. */
    for (int i = 0; i < REPEATS; i++) total++;
    return NULL;
}

int main(void) {
    pthread_t workers[THREAD_COUNT];
    for (int t = 0; t < THREAD_COUNT; t++) {
        pthread_create(&workers[t], NULL, count, NULL);
    }
    for (int t = 0; t < THREAD_COUNT; t++) {
        pthread_join(workers[t], NULL);
    }
    printf("Expected: %lld\n", (long long)THREAD_COUNT * REPEATS);
    printf("Observed: %lld\n", total);
    return 0;
}
