• Advertisement

Archived

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

using threads?

This topic is 6245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how do you use threads in making a win32 application? is it as simple as using threads in java because that''s the only thing i know about threads?

Share this post


Link to post
Share on other sites
Advertisement
There''re two kinds of threads on Win32 platform: one is worker thread; the other is UI thread. Normally, we use a worker thread to process data and request on the back ground.

A worker thread is formed by a normal routine.
e.g.
DWORD MyThread(LPVOID param)
{
....
}

Two methods in Windows Programming are employed to create threads: _beginthread and CreateThread. The former is the C run-time library function, but the rest is Win32 API. It can be easilier implemented in VC than in Java.

David
zwdavid@hotmail.com

Share this post


Link to post
Share on other sites
Actually when counting thread API:s WinNT also support posix threads which is kind of nice since that's a standard also supported by different UN*Xes (== increased portability of the code). To bad Win9x doesn't support them.

pcvsee:
The basic goes something like (using _beginthread()):

void MyThread(void *args)
{
// do thread stuff
}

void StartMyThread()
{
HANDLE hThread = (HANDLE)_beginthread(MyThread, 0, NULL);
// do some more stuff
// then wait for the thread to exit
WaitForSingleObject(hThread, INFINITE);
}

But multi-thread programming is complicated stuff, so I recommend reading a good book or so on the subject.

/Andreas

Edited by - amag on January 15, 2001 1:06:23 PM

Share this post


Link to post
Share on other sites

  • Advertisement