-
September 21st, 2004, 06:13 PM
#1
Best way for worker to gain access to variables set by GUI?
I am converting my project from single to multi-threaded. The single threaded version has lots and lots of variables all in the dialog's class that get set by the GUI. The new worker thread consists of several functions that must use all of these variables.
I am in the process of creating a container class that is made up of all of these variables and then either passing a copy of it to the thread function or making it global (I'll probably end up making it global so the variables dont' have to be passed to each function - call me lazy if you will. )
Am I going about this a good way, or is there a better (less code editing, safer, etc.) way of doing it? I'm pretty sure that I should not access the variables inside the dialog class from the worker thread - hence this effort - is that correct?
Thanks
-
September 21st, 2004, 06:37 PM
#2
Re: Best way for worker to gain access to variables set by GUI?
One solution is pointer and data synchronization.
Kuphryn
-
September 21st, 2004, 10:14 PM
#3
Re: Best way for worker to gain access to variables set by GUI?
Well....the most straight-forward solution is to make all the functions that are used by that thread part of the GUI class. Make the thread function itself a static member of the GUI class. Pass the 'this' pointer at creation time to the thread and use it inside the thread to call the necessary functions. That way, there is neither the need to pass all the variables to either the thread or its functions....
-
September 21st, 2004, 10:23 PM
#4
Re: Best way for worker to gain access to variables set by GUI?
Originally Posted by Andreas Masur
Well....the most straight-forward solution is to make all the functions that are used by that thread part of the GUI class. Make the thread function itself a static member of the GUI class. Pass the 'this' pointer at creation time to the thread and use it inside the thread to call the necessary functions. That way, there is neither the need to pass all the variables to either the thread or its functions....
Just what I was looking for. Thank you, sire!
-
September 22nd, 2004, 09:22 AM
#5
Re: Best way for worker to gain access to variables set by GUI?
Originally Posted by ecspansion
Just what I was looking for. Thank you, sire!
You are welcome...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|