):
-
Are you and Scholar247 the same person? If so please request removal of one profile. As to your questions:
- This site does not provide code to order. Google is the place for samples.
- The consequences of a race condition may vary from incorrect results, to a program not responding.
- There are many different situations when this may be appropriate, but it depends on the problem to be solved.
- Impossible to answer as any problem's ease of resolution depends on a lot of factors.
-
int g_x = 0; DWORD WINAPI Add(void* p) //p unused parameter { g_x++; } void main() { HANDLE m_hArr[10]; int i = 0; for( ; i < 10; i++ ) { CreateThread( NULL,0,Add,NULL,0,&m_hArr[i]); } //Wait for all the 10 threads to complete its execution ::WaitForMultipleObjects(10,m_hArr,TRUE,INDEFENITE); //Now print the result.You expect 10 but it may not be... :) cout<<"g_x = "<
-
Because the order of the execution. Suppose you have 4 floats a,b,c,d and you want to sum up them. In case of serial implementation, it will be like a + b + c + d But in case of parallel, it may execute like (a+b) + (c+d) So the result wont be same. This answers your 4th question.
-
2. Consequence of race condition: Your resource will go to a corrupted state. Not getting the expected result etc.,