Multithreading? Help!
-
Hi All, I am studying multithreading with Visual Studio 2005. I have an error with one sample from "Multithreading Applications in Win32 - Jim Beveridge & Robert" 1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)' /* SerarhFil.cpp */ #include #include #include #include #include #include "MtVerify.h" DWORD WINAPI SearchProc(void *arg); #define MAX_THREADS 3 HANDLE hThreadLimitSemaphore; char szSearchFor[1024]; int main(int argc, char *argv[]) { WIN32_FIND_DATA* lpFindData; HANDLE hFindFile; HANDLE hThread; DWORD dummy; int i; if(argc != 2) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } strcpy(szSearchFor, argv[1]); lpFindData = (WIN32_FIND_DATA*) calloc(1, sizeof(WIN32_FIND_DATA)); MTVERFY(hThreadLimitSemaphore = CreateSemaphore(NULL, MAX_THREADS, MAX_THREADS, NULL)); hFindFile = FindFirstFile("*.c", lpFindData); if(hFindFile == INVALID_HANDLE_VALUE); return EXIT_FAILURE; do{ WaitForSingleObject(hThreadLimitSemaphore, INFINITE); //HERE MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy)); MTVERFY(CloseHandle(hThread)); lpFindData =(WIN32_FIND_DATA*)calloc(1, sizeof(WIN32_FIND_DATA)); }while(FindNextFile(hFindFile, lpFindData)); FindClose(hFindFile); for(i=0; icFileName, "r"); if(!ptrFile) return EXIT_FAILURE; while(fgets(buff, sizeof(buff), ptrFile)) { if(strstr(buff,szSearchFor)) printf("%s: %s", lpFindData->cFileName, buff); } fclose(ptrFile); free(lpFindData); MTVERFY(ReleaseSemaphore(hThreadLimitSemaphore, 1, NULL)); }
Yonggoo
-
Hi All, I am studying multithreading with Visual Studio 2005. I have an error with one sample from "Multithreading Applications in Win32 - Jim Beveridge & Robert" 1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)' /* SerarhFil.cpp */ #include #include #include #include #include #include "MtVerify.h" DWORD WINAPI SearchProc(void *arg); #define MAX_THREADS 3 HANDLE hThreadLimitSemaphore; char szSearchFor[1024]; int main(int argc, char *argv[]) { WIN32_FIND_DATA* lpFindData; HANDLE hFindFile; HANDLE hThread; DWORD dummy; int i; if(argc != 2) { printf("Usage: %s \n", argv[0]); return EXIT_FAILURE; } strcpy(szSearchFor, argv[1]); lpFindData = (WIN32_FIND_DATA*) calloc(1, sizeof(WIN32_FIND_DATA)); MTVERFY(hThreadLimitSemaphore = CreateSemaphore(NULL, MAX_THREADS, MAX_THREADS, NULL)); hFindFile = FindFirstFile("*.c", lpFindData); if(hFindFile == INVALID_HANDLE_VALUE); return EXIT_FAILURE; do{ WaitForSingleObject(hThreadLimitSemaphore, INFINITE); //HERE MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy)); MTVERFY(CloseHandle(hThread)); lpFindData =(WIN32_FIND_DATA*)calloc(1, sizeof(WIN32_FIND_DATA)); }while(FindNextFile(hFindFile, lpFindData)); FindClose(hFindFile); for(i=0; icFileName, "r"); if(!ptrFile) return EXIT_FAILURE; while(fgets(buff, sizeof(buff), ptrFile)) { if(strstr(buff,szSearchFor)) printf("%s: %s", lpFindData->cFileName, buff); } fclose(ptrFile); free(lpFindData); MTVERFY(ReleaseSemaphore(hThreadLimitSemaphore, 1, NULL)); }
Yonggoo
Yonggoo wrote:
1>.\SearchFile.cpp(44) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'DWORD (__stdcall *)(void *)' to 'unsigned int (__stdcall *)(void *)'
Yonggoo wrote:
MTVERFY(hThread = (HANDLE) _beginthreadex(NULL, 0, SearchProc, lpFindData, 0, &dummy));
Yonggoo wrote:
DWORD _stdcall SearchProc(void *arg)
_beginthreadex
requires the thread proc that it calls to return anunsigned int
. You are passing it a function that returns aDWORD
. There is no built in conversion from aDWORD
to anunsigned int
. Change the return type of theSearchProc
to anunsigned int
.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!