Monday 15 February 2010

c - Allocation of pthread stack in glibc -


Possix threads usually share address space but each thread has its own stack. How is this stack allocated? I looked at the allocate_stack function in glibc but I did not understand it. Is the location address shared, because access to the stack of another thread is possible?

Thank you in advance!

Actually, this is possible. For example:

  #include & lt; Signal.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Pthread.h & gt; Zero * f (Zero * arg) {int * p = (int *) arg; * P = 10; Return tap; } Int main () {pthread_t t; Int var = 5; Pthread_create (& amp; t, NULL, f, & var); Pthread_join (t, null); Printf ("var =% d \ n", above); Return (0); }  

output will be "var = 10", no 5


No comments:

Post a Comment