R
Richard MSL
I have a legacy project with hundreds of unmanaged C programs, that I am
porting to .NET. There are a lot of globally scoped variables in the C
programs, which I have had to convert to thread local, so that multiple
threads of the same program do not interfere with each other. The syntax is
like this:
system.h contains:
#define Thread __declspec(thread)
prog1.c contains:
Thread int abc;
prog2.c contains:
Thread extern int abc;
That all works fine, when all the references to the variable have the Thread
prefix. The problem is when something is missing, and it is like this:
prog1.c contains:
Thread int abc;
prog2.c contains:
extern int abc;
In this case, the compiler treats them as totally separate variables, with
separate storage, which causes the program to crash in hard-to-fix ways. I
had expected that the linker would consider the extern int abc; to be an
unresolved external, since it considers it different than the Thread int
abc;, but it does not. It links with no error or warning, then crashes when
run. It will be difficult and unreliable for me to find all the instances of
this, I was hoping that they was a way of getting the linker to detect these,
or a way of making the extern int abc; be made to refer to the Thread int,
without having to find each instance in the source code. I appreciate any
suggestions anyone has.
porting to .NET. There are a lot of globally scoped variables in the C
programs, which I have had to convert to thread local, so that multiple
threads of the same program do not interfere with each other. The syntax is
like this:
system.h contains:
#define Thread __declspec(thread)
prog1.c contains:
Thread int abc;
prog2.c contains:
Thread extern int abc;
That all works fine, when all the references to the variable have the Thread
prefix. The problem is when something is missing, and it is like this:
prog1.c contains:
Thread int abc;
prog2.c contains:
extern int abc;
In this case, the compiler treats them as totally separate variables, with
separate storage, which causes the program to crash in hard-to-fix ways. I
had expected that the linker would consider the extern int abc; to be an
unresolved external, since it considers it different than the Thread int
abc;, but it does not. It links with no error or warning, then crashes when
run. It will be difficult and unreliable for me to find all the instances of
this, I was hoping that they was a way of getting the linker to detect these,
or a way of making the extern int abc; be made to refer to the Thread int,
without having to find each instance in the source code. I appreciate any
suggestions anyone has.