can thread return a local variable?
thread_fuc returns a local variable, it's right? thanks.
//////////////////////////////////////////////////////////////////////////////////////////
#include <pthread.h>
#include <stdio.h>
void *thread_fuc(void *arg)
{
int rtn = *((int*)arg);
rtn *= rtn;
return (void *)rtn; // return a local variable, is it right?
}
int main()
{
int num = 2;
int result = 0;
pthread_t thread_id = 0;
pthread_create(&thread_id, NULL, &thread_fuc, (void *)&num);
pthread_join(thread_id, (void **)&result);
printf("result is :%d\n", result);
}
|