I have two shared global variables
int a = 0;int b = 0;
and two threads
// thread 1for (int i = 0; i < 10; ++i) { EnterCriticalSection(§); a++; b++; std::cout << a ""<< b << std::endl; LeaveCriticalSection(§);}// thread2for (int i = 0; i < 10; ++i) { EnterCriticalSection(§); a--; b--; std::cout << a ""<< b << std::endl; LeaveCriticalSection(§);}
The code always prints the following output
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0
That is quite strange, looks like threads are working sequentally.. What's the problem with that?
Thanks.