Sorry for the uninformative title, but here's my problem I want to do (the example I'm providing is very similar to John the Ripper cracking utility, where you press the spacebar and it prints some data). I made a little picture of what I think my program should look like (graphic representation) here: http://img.photobucket.com/albums/v2...o1/threads.jpg
So, the problem is that I need this data generator thread to be spinning away somewhere, while another (thread? just the parent?) is waiting for an event like keyboard input to do something else. So, I don't even know where to start on this one. Critical sections sound interesting, mutexes also, but all in all I don't know where to look for a solution to my problem. MSDN is an infinite library of information but I don't know how I would go about applying the things given. With my limited knowledge, I was able to create this very simple simple thread:
Code:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
string s = "aaaa";
DWORD WINAPI Generator(void *Params) {
// This is just an example section
// to spit out some data to query
// or something
int i = 0;
int length = s.length();
while(s[i]++)
{
while(s[i] == 'z' + 1) {
s[i] = 'a';
s[++i]++;
}
if(i == length) { break; }
i = 0;
}
return 0;
}
int main(int argc, char* argv[]) {
HANDLE hThread;
DWORD dwThread;
hThread = CreateThread(NULL, NULL,
Generator, // Function pointer
(void*) 0, // Arguments
NULL, &dwThread);
if (hThread) { return WaitForSingleObject(hThread,INFINITE); }
else { return 1; }
}
This just runs the function in a thread and then let's the WaitForSingleObject run infinitely until it returns. Naturally instead of this WaitForSingleObject, I want to be able to interact with this thread or something, or set up another thread which does stuff while this other thread is spinning about, and I have really, no direction for doing something like that. Any tips? It's all greatly appreciated.