Will no-lock crash the program?what about multi-core?
let me put this simple:
To a shared global ingeter variable i;
there is only one thread write to it, like these:
there are many other thread read it, like these:
int temp = i + 100;
//or any number of readonly sentances
I DO NOT even use NO MUTEX in my program!
will my program crash? in multi-core?
In single-core, I figure it absolutely will not crash.
but in multi-core, multiple CPU access one memory unit at the same moment? what happen?
below I have a clearer case:
if multiple threads(for example 1000 threads) are doing "i=100;" at the same moment?
in multi-core CPU, will the program crash without LOCK!?
I know that a program with many threads doing "i=100;" seams quite meaningless; and also I can write a program and run it for months for testing its not crashing, but without theoretic analysis on "why programs failed sooner of later without LOCK"(people told me that, I come here for WHY), I still feel bewildered when the test program crashed after a year.
Who can tell me will this make a program(with atomic access of shared variable) crash ? If yes, why it crashes?
I summarize my points:
Is there any mechanism in OS avoiding multiple threads access a shared global variable at the same moment?
Is there any mechanism is OS avoiding program crashing under the above situation?
I presume that these access(read or write) is atomic, but does 'being atomic' mean that my program will definitely NOT crash or MAYBE crash? how about in multi-core situation?
Also, I can figure an application where I can use this shared variable no-lock accessing:
think about a application-layer routing program like this:
one thread forwarding every incoming udp packet to 200 outgoing destination according to a 'route-table'(like a 200-elements-int-array standing for 200 different destination);
another thread change the same 'route-table'
I want the first forwarding thread use NO LOCK; it's just traversing the array and forwarding packets for performance reason. I can tolerate the indistinct of route-table at some moment. But just don't crash, please!? but I''m not sure whether OS allow me to do so?
CAN ANYONE DEFINITELY TELL ME:
will MULTIPLE-THREADS-ATOMIC-ACCESS-SHARED-VARIABLE crash a program? and WHY? and how about in multi-core CPU?
Is this possible or totally a silly idea? Please, give me help!?:confused: