Click to See Complete Forum and Search --> : Check this out, maybe U can help me?


June 1st, 1999, 05:34 PM
Greetings!

I have a listview app, that displays student data. Each student has an item in the view associated with that student, of which the unique studno is the first column in the view. The actual student data is kept in a student array in the Document class, adhering to the Doc/View paradigm.
Now I have two (or more) threads of which the main thread is the GUI thread, while the other(s) are worker thread(s). The student array is obviously a shared resource, and care must be taken not to have multiple threads accessing it at the same time. But that's relatively straight forward. My problem is that how do I, inside a worker thread, modify the student array, AND the related listview item in the view? Can/should a worker thread modify a view? Isn't that the job of the main (GUI) thread? But how do I sync the two? I don't know how to go about updating the data (array of students) and the listview item(s) that are representative of those students inside a thread other than the main thread. You're probably asking, why I have to do it inside a thread...I mean what's the need for the threads anyway? Well I need this to work before I tackle the original problem, which is quite similiar.

If anyone has any ideas or guidelines - plz let me know.
Thanks in advance.

June 2nd, 1999, 02:54 AM
I tackled a similar problem once, and here's what worked for me:

(1) I locked the list updating routines using CSingleLock so that I didn't have to worry about the list getting whacked by more than one thread at a time. Any code that modified the list contents was protected; I actually ended up with a single updateList() method in my view that would update either a single item (based on the Hint param) or the entire list (if the Hint param was NULL).

(2) I had the GUI thread treat the item data as read-only, and allowed only the worker thread to add/update it. This way I didn't have to worry about locking/unlocking access to the actual data; my case may have been simpler than yours, though, because the worker thread was not allowed to delete anything.

(3) I had the worker thread post a message to the GUI thread to signal that a list item was ready to be updated in the view. That way, the GUI thread would automagically serialize the updates (or just gather them all into a single mass update) without worrying about the worker thread stomping on everything. I later modified the worker thread to examine the message queue to avoid posting redundant update messages if there was already one pending.

Hope this helps.

Cheers!
Humble Programmer
,,,^..^,,,
neusel@ntmail.eucom.mil