I read that threads share the memory address space of it's parent thread. If that is true , why can't a thread function access a local variable belonging to it's parent thread ?
void* PrintVar(void* arg){
printf( "%d\n", a);
}
int main(int argc, char*argv[]) {
int a;
a = 10;
pthread_t thr;
pthread_create( &thr, NULL, PrintVar, NULL );
}
If the thread shares the address space , then the function PrintVar should have been able to print the value of variable a
, right ?
I read this piece of info on http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
Threads in the same process share: Process instructions Most data open files (descriptors) signals and signal handlers current working directory User and group id
If that is true, then why does int a
not qualify as a shared variable ?
I'd like to see an example code where the file descriptors are shared