Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thread issues 1

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
0
0
US
Hello, I am using a thread, my problem is that I need to both pass a character buffer to the thread and recieve an event notifying me when the thread is done with its task.

I create the thread with

unsigned long m_ulIDThread;
HANDLE m_hThread;

m_hThread = CreateThread(NULL,0, WriteToFile,(void*)OutputBuffer,0,&m_ulIDThread);

this allows me to pass in the buffer, the problem is though that I also need to pass in a handle to an event so that it can be set when the thread is done. any ideas.
thanks for the help.
 
Put the buffer pointer and event handle in a structure, then pass a pointer to that structure to the thread.

Make sure that the scope of the structure lasts for the duration of the thread. A good way to ensure this is to use new to allocate it.

Code:
struct foo { char *buff, void *event };

foo *temp = new foo;
temp->buff = OutputBuffer;
temp->event = event;
m_hThread = CreateThread(NULL,0, WriteToFile,(void*)temp,0,&m_ulIDThread);
The thread itself would delete that pointer when its finished with it.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top