|
|||
putting values in void *arglist
hi ,
i want to run a threads using _beginthread(...) (no MFC) inside the threadfunc i want to call a function with many variables. how do i use the void *arglist so it points to a few variables ? i hope my question makes sence thank u |
#2
|
||||
|
||||
Re: putting values in void *arglist
Quote:
You would then use the void* to pass the pointer to an instance of that class or struct, which you would have to cast back to the actual type before accessing the members.
__________________
Guido Stercken-Sorrenti |
#3
|
|||
|
|||
thanks!
|
#4
|
|||
|
|||
i call a function :
Code:
bool MapViewInit(GEO p1, GEO p2, DISPLAY Disp, CONTROL Ctrl, HINSTANCE hInst) { MapThreadArgList maparglist; ////????? maparglist.Ctrl=Ctrl; maparglist.Disp=Disp; maparglist.p1=p1; maparglist.p2=p2; maparglist.hInst=hInst; HANDLE handle1 =(HANDLE)_beginthread( MapThreadFunc,0,
Code:
void MapThreadFunc( void* args ) { GEO p1; GEO p2; DISPLAY Disp; CONTROL Ctrl; HINSTANCE hInst; MapThreadArgList arglist = *((MapThreadArgList*)args); p1=arglist.p1; p2=arglist.p2; Disp=arglist.Disp; Ctrl=arglist.Ctrl; hInst=arglist.hInst; ... ... ... what am i doing wrong? |
#5
|
||||
|
||||
Quote:
scope (when you return from MapViewInit()). Allocate it on the heap, or keep it as a member variable instead.
__________________
Guido Stercken-Sorrenti |
#6
|
|||
|
|||
thanks , it now works
|
결론
구조체를 사용하여 쓰레드에 넘겨줄 인수를 모두 넣는다. (구조체 정의를 전역변수로 해야 함)
구조체의 객체를 만든 다음 객체멤버에 값을 넣어준다.
통째로 객체를 넘겨준다.
스레드에서 구조체의 객체를 만들어 파라메터의 객체를 받는다.
쓰면된다~
'Development > C/C++' 카테고리의 다른 글
[Mutex Thread 동기화 예제] (0) | 2011.11.30 |
---|---|
[Sleep함수] (0) | 2011.11.29 |
[CreateThread(), _beginthread(), _beginthreadex()의 차이] (0) | 2011.11.22 |
[select FD_SET FD_Zero FD_Clr FD_IsSet] (0) | 2011.11.22 |
[_beginthreadex 형변환문제] (0) | 2011.11.22 |