On Saturday 26 February 2005 10:35 pm, Jaydeep Chokshi wrote: > Now as i know every thread run in the same address > space of parent(correct me if goin wrong). now process > address space consist of 1) Executable code (e.g., the > program's instructions), 2) Stack space for local > variables and 3) Heap space for global variables and > dynamically allocated memory and In Unix, heap space > is further broken down into BSS (contains variables > initialized to 0) and DATA sections (initialized > variables and other constants). now which part of this > address space is shared with thread? or in which part > of address space thread will run. All the threads of a process are using the same address space. However, each thread is using it's own stack (but all the stacks of the threads are shared withing the same address space). > Now the programming mechanism of thread is somewhat as > follows, > call to pthread_create(id,attr,fuc-pointer,args) > now when a thread is created the apprpriate function > is called thru that func-pointer right. then how come > v say that thread is running in parent address space > because the programme code is diffrent in that > function body then wat it would be in parent. its ok > that thread must have local stack for the local > variables..also it would share the heap for > dynamically allocated memory...I meant why we say > thread say as lightweight process... > I think your confusion is caused by improper understanding of the address space concept. Simply put, the address space is the way the process/threads are seeing the (virtual) memory. If a thread of process P is accessing the memory at location X it will get the same value as the other threads of the same process. If threads of another process, Q, are accessing the memory at the same location, they might get different values (and most of the time they do) as the two processes P and Q are using separate address spaces. > Now another confusion is suppose if we have forked > multiple processes then would the all share the global > memory or get a unique copy of that? Processes have separate address spaces. When you fork() a process, the child will get a copy of the address space. > how about threads? > Threads shares the address space of their process. > last but not least, is ther any difference between > heap memory and wat we say global memoey.. > When I think of heap memory I think of dynamically allocated memory. I am not familiar with the term global memory, but if you are referring to global variables, they are not part of the heap. tavi PS: To throughly understand these concept you should read a good operating systems book. Tanenbaum's "Modern Operating Systems" is one of them. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/