Solved

Problem with scope in MFC

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now