I'm really new to multi-thread programming. Really confused about the definition. Say I have two threads
x, y, z = 0;
Thread 1:
lock(x);
lock(y);
x = y + 1;
unlock(x);
unlock(y);
Thread 2:
lock(x);
lock(z);
z = x + 1;
unlock(x);
unlock(z);
You can see that the value of z is dependent on which thread execute first. If thread 1 happens before thread 2, z = 2; if thread 2 executes first, z = 1. According to many existing answers, e.g. Is this a race condition?, I believe many people think it's not. But the result is unpredictable - depend on thread scheduling still sounds weird to me. It this a semantic mistake? Do people ever write multi-thread programs like this? Thanks for any comments!!