[LCP]Blocking malloc
Hemant Mohan
hemantm at pune.tcs.co.in
Thu Apr 11 15:49:06 UTC 2002
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
More information about the linuxCprogramming
mailing list