Archived

This topic is now archived and is closed to further replies.

CtrlAltDel

Threads...

Recommended Posts

HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);


Looking at create thread, I see that you can pass values thru LPVOID lpParameter, how can I pass more than one value using create thread?

Also the following code would create two threads that would run at the same time, and so I could run 3 functions at one time?(The two process I created, along with the one that starts when the program is executed)?

hThread = CreateThread(
NULL,
0,
ThreadFunc,
&dwThrdParam,
0,
&dwThreadId);

hThread2 = CreateThread(
NULL,
0,
ThreadFunc2,
&dwThrdParam,
0,
&dwThreadId);

Share this post


Link to post
Share on other sites
quote:
Original post by CtrlAltDel
Looking at create thread, I see that you can pass values thru LPVOID lpParameter, how can I pass more than one value using create thread?


Pass a pointer to a structure, and populate that structure with all your input and output values. The calling thread fills-in the inputs, the worker thread fills-in the outputs.

quote:

Also the following code would create two threads that would run at the same time, and so I could run 3 functions at one time?


Yep.

Share this post


Link to post
Share on other sites
quote:
Original post by CtrlAltDel
Looking at CreateThread, I see that you can pass values thru LPVOID lpParameter, how can I pass more than one value using create thread?

Pack them up in a struct and pass a pointer to that struct to CreateThread[Ex].

quote:

Also the following code would create two threads that would run at the same time, and so I could run 3 functions at one time?(The two process I created, along with the one that starts when the program is executed)?

Basically, but beware of race conditions and deadlocks. You''re passing the same data to both CreateThread calls. You need to somehow synchronize access to the variable memory; see mutexes, semaphores and critical blocks.

Share this post


Link to post
Share on other sites