I am teaching OSC (Operating System Concepts). It is difficult to explain concepts of threads or processes for student. I am looking for some programs which simulate these problems.Reply
Originally posted by: Fu Qiang
In context exchange,how does the memory data and resource distributing change? Could diffient threads deal with the same resource? Thanks a lot
Originally posted by: Erhard Henkes
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?
Originally posted by: George Gao
It is too important!
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.
Code:
Declare the thread function in your header as:
static UINT MyThreadFunc(LPVOID parent);
to start the thread:
AfxBeginThread(MyThreadFunc,(LPVOID)this);
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)
CMyDlg* pParent=(CMyDlg*)parent;
...Do something
pParent->CMyDlg.m_txtCaption.SetWindowText("All Done!");
return 0;
}
Originally posted by: DarkenMind
Hi,
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...
Originally posted by: Shimla
Hi
I have written a dll code in C++ and i need to call a vb.exe
inside of that. Can I do that ?
Originally posted by: Mahesh
A very good explanation. It will be too good if the states of the threads are explained in detail
Originally posted by: MIchael Ackermann
I agree with Nikhil that some sample code snippents may be a good idea, even maybe ideas of where we could implement threads, or a practice program to see how threads are implemented
Originally posted by: Satish
A good start on Threads.
Originally posted by: Nikhil alulkar
Hi,
I would to share a information,
Unlike Unix based o.s. win 32 thread are not light weight.