In my class I have a float function that should work always and return value to use it in other place, but I can't create thread for this float function
Leaving aside for the moment that pthread knows nothing about classes, your getload() would need to be a static function to be callable from pthread_create.
1 2 3 4 5 6 7
pthread_create(&th, NULL, getload, NULL);
// wait around for a while
void *result;
pthread_join(th, &result);
float *answer = reinterpret_cast<float*> (result);
// use the answer
delete answer;
@salem c, Thanks for the help but I still have a problem, now the issue is thread is run but does not get sleep and the result is not returned, I think because of for/while(true) I should use pthread_detach(th);