Re: 1 function seen as 2
Frank Birbacher wrote:
Cristiano schrieb:
I have many module cpp with many functions.
I need to call these functions from 2 threads.
I'd like to do something to tell the compiler that each thread has
its own functions.
Do the functions use global variables? Does the word "static" occur in
your functions?
No, but I didn't write the code with the shared functions, so I don't know
the code very well. I wrote the code which uses the shared functions.
If not then you may probably call the same function from different
threads.
I already seen that my application crashes in multi-thread mode. There are
many shared functions with parameter passing (is an FFT library) and the
code "as is" cannot work.
Example:
[...]
char* makeString(int i)
{
static char result[5] = {0}; //like global data
result[0] = i<5 ? 'A' : 'B'; //not thread safe
return result;
}
That fails also without the static result[] when changed this way:
char* makeString(int i)
{
char result[5] = {0};
result[0] = i<5 ? 'A' : 'B'; //not thread safe
// Do something with i and/or result
// When the thread 1 is here and the thread 2 calls
// this function i and result are corrupted :-(
return result;
}
All the functions are like that.
Thank you
Cristiano