bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Thread has inconsistent object state


From: Daniel Hahn
Subject: Thread has inconsistent object state
Date: Tue, 04 Nov 2003 11:15:10 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624

Hi,

I have the problem that under certain circustance my Thread object will have inconsisten object states - this is only under WIN32 with Visual Studio .NET (7.1), Linux/gcc-3.3 seems to work.

Here is it: I have a singleton class like this

class Single : public Thread {

static Single& getInstance() { return myInstance; }

void init() {
   x = 23;
   cout  << "Init: x is " << x;
}

void run() {
   cout << "Thread running, x is " << x;
}

private:
   int x;
   static Single myInstance;
   Single() {
       x=17;
       cout << "Constructor: x is " << x";
   }
} // End of class

If I use this class and call:

Single& single = Single::getInstance();
single.init();
single.start();

I will get the follwing result:
> Constructor: x is 17
> Init: x is 23
> Thread running, x is 17

It seems like the Thread that is started has a different data set then the object I was working with before. I have no idea why that is so...

Regards,
                                    Daniel Hahn





reply via email to

[Prev in Thread] Current Thread [Next in Thread]