Question: #include #include DWORD Sum; /*data is shared by the thread(s)*/ /* the thread runs in this separeate funtion */ DWORD WINAPI Summation(LPVOID Param) { DWORD

#include #include DWORD Sum; /*data is shared by the thread(s)*/ /* the thread runs in this separeate funtion */

DWORD WINAPI Summation(LPVOID Param) { DWORD Upper = *(DWORD*)Param; for (DWORD i = 0; i <= Upper; i++) Sum += i; return 0; } int main(int argc, char *argv[] ) { DWORD ThreadId; HANDLE ThreadHandle; int Param; /*perform some basic error checking*/ if (argc != 2){ fprintf(stderr, "An integer parmeter is required "); return -1; } Param = atoi(argv[1]); if (Param < 0){ fprintf(stderr, "An integer >= 0 is required "); return -1; }

//create the thread ThreadHandle = CreateThread( NULL, //Defualt security attributes 0, //default stack size Summation, //thread function &Param,//parameter to thread function 0, //default creation flags &ThreadId) ; //returns the thread identifier

if(ThreadHandle != NULL){ //now wait for thread to finish WaitForSingleObject(ThreadHandle, INFINITE);

//Close Thread handle CloseHandle(ThreadHandle); printf("sum= %d ", Sum); } }

I don't know why my program just jump right to the first error messaage, it's not displaying the summation

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!