c - sqrt() in threaded environment returns nan when it should not -


the code below part of threaded function pass output data array. in square root function have sum of 2 squares means values inside of brackets never negative. somehow of values in output nan.

for(i=0; i<n; i++) {     fft_out[1][i] = sqrt((data->base[i].re * data->base[i].re) +                          (data->base[i].im * data->base[i].im));     printf("%d - %f - %f - %f\n",            i,            data->base[i].re*data->base[i].re,            data->base[i].im*data->base[i].im,            sqrt((data->base[i].re * data->base[i].re)+                 (data->base[i].im * data->base[i].im))); } 

printf

you must sure vars used in threads, eg. loop indices used access arrays, private calling thread when need be, eg. automatic storage or thread-local.

in code, possible 'i', if not private thread changed thread while sqrt() expression being evaluated, resulting in taking square root of negative number:(


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -