[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Realloc is blocking execution



On Wednesday 14 October 2009 07:50:06 Mats Erik Andersson wrote:
> onsdag den 14 oktober 2009 klockan 13:54 skrev ERSEK Laszlo detta:
> > On Wed, 14 Oct 2009, Goswin von Brederlow wrote:
> > >Mats Erik Andersson <mats.andersson@gisladisker.se> writes:
> > >>Is this unavoidable fact that realloc() blocks execution
> > >>a known issue with gcc-4.3.2 or glibc-2.7?
> > >>Personally, I was under the impression that
> > >>malloc/realloc never should block execution,
> > >>but would instead return NULL. That Etch and
> > >>Lenny behave oppositely disturbs me very much.
> > >
> > >What do you mean by "block execution"?
> > >
> > >If you mean it takes a while to return then I guess that just means
> > >you now have a case where memory is copied while before there was free
> > >space after the allocation.
> >
> > I suppose even massive memory copying and/or swap activity would hardly
> > delay the gcc process so much that it would be distinguishable from
> > "normal" gcc behavior. Perhaps Mats means "the gcc process hangs
> > indefinitely in realloc()"?
> >
> > Mats, how do you know it's realloc()? Can you try "strace gcc"?
> >
> > Cheers,
> > lacos
>
> I inserted two printouts, immediately surrounding realloc():
>
>         fprintf(stderr, "Will enter realloc().\n");
>
> 	ptr = realloc(ptrold, 1024)
>
> 	fprintf(stderr, "Has exited realloc().\n");
>
> Only the first statement gets printed. In addition, the machine
> I run the test on, has 1 GB physical memory, yet refuses to reallocate
> a meager 1 kB. I am the sole user on the system, execept for the few
> background services I use to test the programs I develop.
> The inability to release 1 kB memory for usage made me wondering about
> bugs.
>
> Regards
>
> Mats Erik Andersson, fil. dr

I would compile with the -g option and run through the program with gdb.   realloc can fail if ptrold was not populated by malloc or 
calloc originally and therefore doesn't have a proper header.   If ptr is null then maybe your program is segfaulting beore the 
second fprintf is executing.   in gdb you will be able to examine ptrold before executing.  If it is null then realloc is 
essentially a call to malloc(1024).  Then after stepping through the realloc examine ptr and see if it is null.   If in gdb it hangs 
then hit ^C and trigger an interrupt.   You can use backtrace and actually determine where in realloc it is hanging.



-- 
Mr. Clare Jarvis
President, Jarvis Computer Software
PO Box 1264
Winona, MN 5598707264

(507) 454-2575


Reply to: