Bug 3439 - uClibc 0.9.28 pthread, malloc, fork
Summary: uClibc 0.9.28 pthread, malloc, fork
Status: NEW
Alias: None
Product: uClibc
Classification: Unclassified
Component: Threads (show other bugs)
Version: <= 0.9.29.x
Hardware: PC Windows
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-09 07:15 UTC by Sergey
Modified: 2011-03-10 08:06 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey 2011-03-09 07:15:40 UTC
- pthread allocates memory in a loop
 - at the same time fork is run in a loop
 - when this sample is compiled against uClibc 0.9.28 and run, it hangs (fork() does not return child)
 - by adding usleep(1) before p = malloc(1) helps.

Any hints ?

#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<pthread.h>


void *run(void *foo)
{
        int i, j, k;
        void *p;

        for (i = 0; i < 1000; i++)
                for (j = 0; j < 1000; j++)
                        for (k = 0; k < 1000; k++)
                        {
                                p = malloc(1);
                                free(p);
                        }
        pthread_exit(NULL);
}

void main(void)
{
        pthread_t thread;
        int i, pid, status;

        pthread_create(&thread, NULL, run, NULL);

        for (i = 0; i < 1000; i++)
        {
                pid = fork();
                if (pid < 0)
                {
                        printf("fork error\n");
                        break;
                }
                if (pid > 0)
                {
                        printf("fork parent: %d\n", pid);
                        wait(&status);
                }
                if (pid == 0)
                {
                        printf("fork child: %d\n", getpid());
                        exit(0);
                }
        }

        exit(1);
}
Comment 1 Sergey 2011-03-10 08:06:24 UTC
The same code works with uClibc-0.9.31 and LINUXTHREADS_NEW .

Sometimes giving segmentation fault at the end of execution in _pthread_cleanup_push_defer.