
The 'Th' program - Demonstrates threads in Visual C++.

When you first run this program, you will see a white rectangluar area, and an Add and Remove button.  If you click the Add button, a red bar will appear in the white rectangle, and it will be moving up and down.  Each time you click 'Add', a new moving bar is added.

Each bar, is represented in the program by a 'Bar' object.  When you click the 'Add' button, a Bar object is created, and a thread is also created.  In the thread, the Bar object is moved in an up direction, and then in a down direction, repeatedly.  The Bar object, also servers as the 'synch' between the main thread and the child threads.  Values that the child thread changes in the Bar object, are visible to the main thread.  The main thread, takes those values, and puts them on screen in the form of a bar.

The main thread utilizes a time, to periodically check the value of the bars, and display their appearance.  Note, that this to could have been a seperate thread.

To review the source code, look at the following things:

1) The Bar class
2) The CThView::OnAddBar() function
3) The BarThreadProc() function
4) The CThView::OnRemove() function
5) The CThView::Bars data member, used to keep track of the Bar objects.

This is the code that applies to threading.  The rest is timer and display handling.


Mario Giannini

