Question: Receiving the following error in my code: DWORD ( _ _ stdcall * ) ( LPVOID threadNo ) is incompatible with parameter of type
Receiving the following error in my code: DWORD stdcall LPVOID threadNo is incompatible with parameter of type beginthreadexproctype"
#include
#include
#include
#include
bool enableMutex false; Command line parameter
int count ; Actual count after update by threads
unsigned long numberIter ; Command line parameter
HANDLE mutex; Mutex for critical section
DWORD WINAPI threadWorkLPVOID threadNo
int threadID intthreadNo;
for unsigned int i ; i numberIter; i
if enableMutex
WaitForSingleObjectmutex INFINITE;
for int j ; j ; j
count absstaticcastGetCurrentThreadId;
Sleep;
if enableMutex
ReleaseMutexmutex;
std::cout "Thread threadID terminated." std::endl;
return ;
int mainint argc, char argv
Get the command line parameters
if argc
std::cerr "Invalid number of arguments." std::endl;
return ;
int numberOfThreads atoiargv;
numberIter atolargv;
enableMutex atoiargv;
Initialize mutex
if enableMutex
mutex CreateMutexNULL FALSE, NULL;
if mutex NULL
std::cerr "Failed to create mutex." std::endl;
return ;
Create threads
HANDLE threads new HANDLEnumberOfThreads;
int threadIDs new intnumberOfThreads;
for int i ; i numberOfThreads; i
threadIDsi i;
threadsiHANDLEbeginthreadexNULL &threadWork, &threadIDsi NULL;
if threadsi NULL
std::cerr "Failed to create thread i std::endl;
return ;
std::cout "Thread i created." std::endl;
Wait for threads to terminate
WaitForMultipleObjectsnumberOfThreads threads, TRUE, INFINITE;
Output the actual value of count and the theoretical value
std::cout "Actual count count std::endl;
int expectedCount numberOfThreads numberIter numberOfThreads numberOfThreads numberOfThreads;
std::cout "Expected count expectedCount std::endl;
Clean up
if enableMutex
CloseHandlemutex;
delete threads;
delete threadIDs;
return
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
