G
greg wellman
I'm trying to track down a problem in code written by someone else.
The symptom appears to be a form of thread unsafety. Let me write a
little psuedo code
bool firsttime = true;
(some more global declarations)
AnInitFunctionThatEveryThreadRuns()
{
if (firsttime)
{
firsttime = false;
(initialize more globals)
}
}
Now here's the situation - sometimes hours after the first thread, and
many others, have been through this code, two new threads are started
pretty much simultaneously. One would think that because firsttime is
now false, that this function can't do anything so it doesn't matter
that it's technically thread unsafe. However, the globals it
initializes are changing value when these two new threads start and I
can't figure out why.
There is no other place in code that alters those globals, just a
couple that read them. Obviously the problem can't be reproduced while
debugging.
Any ideas?
TIA,
Greg
The symptom appears to be a form of thread unsafety. Let me write a
little psuedo code
bool firsttime = true;
(some more global declarations)
AnInitFunctionThatEveryThreadRuns()
{
if (firsttime)
{
firsttime = false;
(initialize more globals)
}
}
Now here's the situation - sometimes hours after the first thread, and
many others, have been through this code, two new threads are started
pretty much simultaneously. One would think that because firsttime is
now false, that this function can't do anything so it doesn't matter
that it's technically thread unsafe. However, the globals it
initializes are changing value when these two new threads start and I
can't figure out why.
There is no other place in code that alters those globals, just a
couple that read them. Obviously the problem can't be reproduced while
debugging.
Any ideas?
TIA,
Greg