Solved

Problem with scope in MFC

Posted on 2000-04-26
4
323 Views
Last Modified: 2012-08-14
I've created a multithreaded program in MFC.  The worker thread currently sits in the background and loops through a socket function (it's a server) that receives records from an etharnet connection and then parses the information and stores it in a class.  The second thread runs on a timer and is the main GUI and updates itself from the information parsed from the records.  My problem is allowing the GUI to access the information received from the socket.  Since the socket thread runs on its own I cannot access that information.  I'm having a serious scope problem and need help.  Thanks for anything you can offer
0
Comment
Question by:xelpmoc2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 75 total points
ID: 2752304
You need to use global variables or pointers to allow the two threads the opportunity to share the information.  I don't know the exact nature of the data and how it is allocated and managed, so I really say much more than that.

Note that if the two threads will be accessing the data simultaneously you will probably need to synchroize access to the data.  Are you familar with how to do so?  In this case you can probably use a critical section to synchronize access.
0
 
LVL 1

Author Comment

by:xelpmoc2
ID: 2753023
Is it truely as simple as that?  I ask because the person who was helping me on the project informed me that since the thread is running continuously in the background seperate from the rest of the program that accessing the information at will (or off of a timer) would be impossible since the two threads run independantly of each other.  Could using MFC throw a wrench into this also?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2753197
>> Is it truely as simple as that?  
sharing data between multiple threads is usually not that easy 9not THAT hard either).  But the easy part is making it available to both threads (using a global variable, pointer, other mechanism.  the harder part is making it safe to access the data from both threads.  (so the data does not get corrupted)  That will usually require snchronization.  The detaisl of that depend on th eexact nature of the situation.

>>  impossible since the two threads run
>> independantly of each other
That is done al time.

>>Could using MFC throw a wrench into this also
it depends on what you are doing, but probalby not.

Are you familiar with syncronized access in multiple threads.  It is covered in many intermediate/advanced programming texts.   usually it is done using a mutex.
0
 
LVL 1

Author Comment

by:xelpmoc2
ID: 2753231
Thank you nietod, you made my first experience with this web page a good one, it was so nice to get quick and insightful answers.  Thank you so much for your help!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 79
Would like to move button in a function 3 85
VS2015 compilation and missing DLLs 9 181
How to Correctly derive class from CWinThread in MFC 4 89
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question