#include #include long count = 0; void *run(void *n) { long i, nums = *((long *)n); for (i = 0; i < nums; i++) { count++; } return NULL; } void main() { pthread_t t1, t2; long nums = 100000; pthread_create(&t1, NULL, run, &nums); pthread_create(&t2, NULL, run, &nums); pthread_join(t1, NULL); pthread_join(t2, NULL); printf("count = %d", count); } 如果我把 nums 设置为 10000,那么每次都准确输出 20000。或者设置的值比 10000 要少时也能准确输出。如果我把 nums 设置为 100000,那么每次输出的值都好像是随机的,范围在 100000 到 200000 之间。  如果是因为线程之间执行顺序的问题导致输出不确定,那为什么当值为 10000 时输出的值是比较确定的?