2010-03-06 6 views
0

비주얼 스튜디오 C++ 내가 스레드를 사용하고 2008멀티 스레드

. 그러나, 나는이 경고를 가지고 있고 내가 뭘 잘못하고 있는지 확신하지 못한다. 당신이 _beginthreadex에 전달

1. unsigned int (__stdcall *)(void *) differs in levels of indirection from 'void *(__stdcall *)(void *)' 
2. _beginthreadex different types for formal and actual parameters 3 

/* Function prototype */ 
void* WINAPI get_info(void *arg_list) 

DWORD thread_hd; 
DWORD thread_id; 

/* Value to pass to the function */ 
int th_sock_desc = 0; 

/* Create thread */ 
thread_hd = _beginthreadex(NULL, 0, get_info, (void*) th_sock_desc, 0, &thread_id); 
if(thread_hd == 0) 
{ 
    /* Failed to create thread */ 
    fprintf(stderr, "[ %s ] [ %s ] [ %d ]\n", strerror(errno), __func__, __LINE__); 
    return 1; 
} 
+0

(void *) th_sock_desc -> & th_sock_desc? –

+0

반환 값에 대해 CloseHandle()을 호출해야합니다. boost :: thread는 더 나은 쥐덫 일 수 있습니다. –

답변

1

스레드 기능은

DWORD WINAPI ThreadProc(
    __in LPVOID lpParameter 
); 

그래서 당신에게, 당신이 _beginthread

uintptr_t _beginthread( 
    void(*start_address)(void *), 
    unsigned stack_size, 
    void *arglist 
); 
uintptr_t _beginthreadex( 
    void *security, 
    unsigned stack_size, 
    unsigned (*start_address)(void *), 
    void *arglist, 
    unsigned initflag, 
    unsigned *thrdaddr 
); 

그것은 CreateThread가 기대하는 것과 동일합니다에 전달하는 것과 다른 프로토 타입을 가지고 스레드 proc의 함수 서명을

로 변경해야합니다.
unsigned WINAPI get_info(void *arg_list) 

WINAPI은 반환 유형을 변경합니다.

편집 :

WINAPI이 실제로 필요한, 워드 프로세서는 _beginthredex에 대한 잘못된 프로토 타입을 보여 주지만, 그들은 명시 적으로 __stdcall이 필요한 상태. 귀하의 문제는 반환 유형입니다. 또한 오류 메시지는 __stdcall이 예상됨에 따라이를 해결한다고 말합니다.

+0

__stdcall을 지원하므로 WINAPI가 필요하다고 생각했습니다. _beginthreadex가 기대 하듯이. 감사. – ant2009

+0

WINAPI는 __stdcall입니다. _beginthreadex는 __cdecl을 필요로합니다. CreateThread는 __stdcall을 필요로합니다. –

+0

_beginthread는 __cdecl을 필요로합니다. _beginthreadex에서 프로토 타입은 __stdcall (또는 __clrcall)이어야하므로 WINAPI가 좋습니다. –