[LCP]Blocking malloc -- solved
Hemant Mohan
hemantm at pune.tcs.co.in
Tue Apr 16 21:08:06 UTC 2002
Finally I have solved the problem. It was another malloc call in the first
thread that was corrupting the memory.
Thanks a lot for your inputs.
Hemant Mohan
On Tuesday 16 April 2002 11:09, Andrew Weaver wrote:
> Moi hemant, see attached source. Is this what you do (nearly) because it
> works just fine. Could it be that your "function1" exits and takes
> everything else with it?
>
> <<malloctest.c.DOS>>
>
> > -----Original Message-----
> > From: Hemant Mohan [SMTP:hemantm at pune.tcs.co.in]
> > Sent: Thursday, April 11, 2002 8:50 AM
> > To: linuxcprogramming at lists.linux.org.au
> > Subject: [LCP]Blocking malloc
> >
> > Hi,
> >
> > I am stuck up in problem where the malloc is blocking.
> > I am programming in a multithreaded environment, using gcc-3.0.3 under
> > linux.
> > The thread related functions are from a user created library.
> >
> > The program structure is something like this:
> >
> > main()
> > {
> > ....
> > thread_create (function1, ...);
> > ....
> > }
> >
> > function1(...)
> > {
> > ...
> > thread_create(function2, ...)
> > }
> >
> > function2(...)
> > {
> > char* x = NULL;
> > printf("First print\n");
> > if((x = malloc(100*sizeof(char))) == NULL)
> > {
> > printf("second printf, malloc error\n");
> > fflush(stdout);
> > perror("malloc error");
> > }
> > printf("third printf\n");
> > fflush(stdout);
> > ....
> > }
> >
> > My problem is
> > When the program is run we reach the function2 and the first print
>
> message
>
> > is
> > displayed. However after that the program blocks. Neither I get the
>
> second
>
> > print message nor the third one. The program doesn't proceed further.
>
> Even
>
> > there is no error message from the perror. Normally, if the malloc fails
> > then it should return a NULL and we should get the second printf and the
> > malloc error. Else, if the malloc call is successful then the third print
> > should be displayed.
> > Where am I going wrong ? I couldn't find any documentation indicating
>
> any
>
> > condition where malloc can block.
> >
> > Can anyone please help .
> >
> > Thanks,
> > Hemant
> >
> > _______________________________________________
> > This is the Linux C Programming List
> >
> > : http://lists.linux.org.au/listinfo/linuxcprogramming List
>
> (See attached file: malloctest.c.DOS)
More information about the linuxCprogramming
mailing list