Subj : Re: why one stack per thread and one heap for multithread? To : comp.compilers.lcc,comp.programming.threads From : Eric Sosman Date : Fri Feb 25 2005 11:41 am TonY wrote: > Hi, > > why in multithreading, each thread has its own stack, but all share > the same heap? > I understand that one stack is needed for each thread as each could > have its own procedure call. but why we don't associate a heap for > each thread since each thread can also create dynamically its own > data? Thread T1 (producer): ptr = malloc(sizeof *ptr); ptr->data = ...; add_to_shared_queue(ptr); Thread T2 (consumer): ptr = take_from_shared_queue(); do_stuff_with(ptr->data); free(ptr); /* Oops! Not from my heap! */ -- Eric.Sosman@sun.com .