You didn't tell about many waiting threads with equal priority. Which comes first? This one which has waited a longer or a shorter time? To my mind it should be the thread waiting longer, but experiments with Windows 98 show that it is inverse. The thread which has waited at least comes first. How does this work? What is under the hood?
You have a MFC application that needs to populate a something by reading a very large file or database on load. If you did the population in the OnInitDialog the application would apear to not load up until the loading routine was finished. Putting the load routine into a thread and calling it from the OnInitDialog would allow the application to continue as normal and the user could exit the app if they chose to.
Similarly you might have an app that just calculates when a button is clicked. If your calculations max out the CPU then the application will appear to be non-responsive or very sluggish. If you had another button on the app to stop the function you wouldn't be able to click it and the window it's on might even fail to redraw. Putting the calculation routine into a separate thread will allow the rest of the app to be responsive since the thread the window runs in won't be busy doing the calculation.
Declare the thread function in your header as:
static UINT MyThreadFunc(LPVOID parent);
to start the thread:
The thread function itself:
UINT CMyDlg::MyThreadFunc(LPVOID parent)
//Use this pointer to access all of the members of CMyDlg (i.e. Dialog controls, etc)
After I've read some of your comments I guess most want to know where to apply multithreading.
I've got a good example for this:
I'm currently designind an activex-control for loading/displaying/editing images. I have images with 3500x2500 pixels, and, to preserve memory, i will have to convert them from tiff to dib for example. This process is very CPU-intensive, and if you have a multipage-tiff with 6 frames of this dimension, the user waits 1 or 2 minutes, until the first frame is displayed.
So I created a seperate thread, responsible for loading data. It fills a special structure, containing information which frame is already loaded, which is not. As soon as the first frame is loaded, it will be displayed, regardless how much frames there are to load.
I suggest seperate threads everywhere where blocking operation might occur. In my case, if loading of the first frame is to slow, the user can abort the load process...