?
Solved

Problem with scope in MFC

Posted on 2000-04-26
4
Medium Priority
?
325 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 300 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

Independent Software Vendors: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

777 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