P
Patrick Hoffmann
hi folx,
today I had "multithreading" trouble with the following code (MS
VC++6/optimized compiling):
---------------------------
class myclass
{
static int s_nNext;
public:
static int getN() { static int N = s_nNext++; return N; }
};
int myclass::s_nNext = 0;
---------------------------
myclass::getN() increments myclass::s_nNext for one time and returns
it before.
With this code I wanted to create an automatic "class-id-enumeration".
It worked well in a multi threaded enviroment with linux/gcc for a
long time. But today I got problems under VC6++/Windows, because in
this case N seems to be thread local storage. So every thread
(including the main) gets a new id for the same class.
I worked around that problem, but I'm interested in an official
documentation of this issue. Is it part of C++, MS or VC++?
Can anybody give me some acknowlege?
thanx much, keep hack'n!
p@
today I had "multithreading" trouble with the following code (MS
VC++6/optimized compiling):
---------------------------
class myclass
{
static int s_nNext;
public:
static int getN() { static int N = s_nNext++; return N; }
};
int myclass::s_nNext = 0;
---------------------------
myclass::getN() increments myclass::s_nNext for one time and returns
it before.
With this code I wanted to create an automatic "class-id-enumeration".
It worked well in a multi threaded enviroment with linux/gcc for a
long time. But today I got problems under VC6++/Windows, because in
this case N seems to be thread local storage. So every thread
(including the main) gets a new id for the same class.
I worked around that problem, but I'm interested in an official
documentation of this issue. Is it part of C++, MS or VC++?
Can anybody give me some acknowlege?
thanx much, keep hack'n!
p@