Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Common Update Retardation 1

Status
Not open for further replies.

coldneut

Programmer
Apr 19, 2001
11
US
After several days of complete frustration over why my code
wasn't working I finally realized the problem.

I am using some global common variables to exchange data among
different classes. When I enter a new class module (such as a
dialog) I pick up the global variable current values OK. I make a
change to them, then look at them and they are indeed changed
locally. However they are not changed in other class modules
until I exit the dialog. When I re-enter the dialog, I get the
latest global values which are the response to my original intent.
One target of my global variables is a classless thread which
should be in memory executing at all times.

Does anyone out there know a "work around" so global variables
are changed for all modules when changed locally?


 
Can you give a short sample? As far as I understand you have problems with thread's syncronisation. I think you need there critical sections. They are designed just for syncronisations of threads. John Fill
1c.bmp


ivfmd@mail.md
 
John:

Thanks for your response. What I am doing is creating a thread with a subroutine
at the top of a program so as not to be a part of a class. I am using
AfxBeginThread(comCode, (LPVOID) ThreadIdx).

The thread (comcode) works something like this:

int A, B;

UINT comCode(LPVOID ThreadIdx) {

A = 0; B = 0;

while(true) {
if(A == 1) B++;
}

In a piece of dialog code I have as an event handler:

extern int A, B;
MyDilog::test {
char s[20];
A = 1;
sprintf(s,"A = %d, B = %d",A,B);
AfxMessageBox(s);
}

No matter how mant times I press the button to bring up
this event, I see A =1, B=0;

If I exit the whole dialog, and then bring it back up again, lo and
behold A=1 and B has incremented.

I hope this helps. I'm perplexed.

Joe
 
If A is 1 B starts to increment. You will not be able to predict there the value of B, because you are not able to predict how much time A will be 1. John Fill
1c.bmp


ivfmd@mail.md
 
John:

The problem is that B remains 0 while A is 1 as I go in and
out of the event that sets A to 1. B only changes if I completely
exit the dialog and then come back in.

Joe

 
If you open dialog from the thread, this thread stops while dialog is active. It means, runnging of thread switch into dialog's WndProc. John Fill
1c.bmp


ivfmd@mail.md
 
The dialog is not opened from the thread. The thread is run outside
of any class so as not to be hampered by anything else.
 
I don't understand your question. I am settind A=1 in one
of the dialog's event handlers. Afterward I view the result
using AfxMessageBox.
 
Try like following. Maybe it'll help.
extern int A, B;
MyDilog::test {
char s[20];
::A = 1;
John Fill
1c.bmp


ivfmd@mail.md
 
I tried the ::A=1 and there was no difference.

I am thinking along the lines of the thread being suspended
while the dialog is executing. I tried to add
SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_CONTINUOUS)
to the thread and got an error starting program:
"linked to missing export KERNEL32.DLL:SetThreadExecutionState"
(I am using Windows 95) . It scares me to death to think of replacing the
KERNEL32.DLL if I can find a more recent one.

Do you think this is worth pursuing?
 
By the way, how many processors do you have on your computer and what kind of processors? John Fill
1c.bmp


ivfmd@mail.md
 
John:

My computer has one Pentium II. The problem seems to
have corrected itself. I've changed so many things that I
am at a loss as to what fixed it. I think I will let well
enough alone and hope it doesn't reappear. Thanks for
all your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top