Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

Students also viewed these Databases questions

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago

Question

5. What information would the team members need?

Answered: 1 week ago