Hey everyone,

I'm trying to write a simple program that can do more than one thing at once. I'm not an expert on the iostreams, so I don't know if I need to create threads to accomplish what I want.

What I'm trying to do is run a loop while monitoring an istream. I know I could put a getch() at the end(inside) the loop, but if it is a long loop, it will only check the character at the end of the loop, and thats not what I want.

I had found a simple threading code somewhere but I can't find it now!

If anyone can help me figure this out, OR post some simple code on how to create two different threads, it would be helpful.

Thanks for your time.
- Daniel

PS - (Win32 console program with MSVisual Studio 2005 c++)

look at www.microsoft.com for CreateThread() win32 api function. It looks like a lot of parameters but you can leave most of them 0. I don't know if you can use the same stream object between threads or not (not sure if they are thread-safe). Even if they are, the two threads will have to coordinate their access to the stream object -- they cannot both access the same object at the same time. Normally use mutexs for this purpose.

May be u can use these functions they are easy to use..

hThread = _beginthread (ThreadProc, uiStackSize, pParam) ;

It's just a bit simpler and is perfectly fine for most applications. This Thread function has the syntax

void __cdecl ThreadProc (void * pParam) ;

After the _beginthread function is called, the code in that thread function, as well as any other function the thread function might call, runs concurrently with the rest of the code in the program. Two or more threads can use the same function in a process. In this case, the automatic local variables (stored on the stack) are unique to each thread.

This article has been dead for over six months. Start a new discussion instead.