Solved

Problem with scope in MFC

Posted on 2000-04-26
4
324 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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