uclibc pthread problem

Vikas TM vikas.tm at gmail.com
Thu Sep 13 07:30:29 UTC 2007


Hi,

Getting segmenation fault during execution. where i used uclibc-0.9.27
for powerpc processor.
Here is my sample code..
#include <sys/types.h>
#include <pthread.h>
pthread_t install_pthread = 0;
int install_from_url(const char *url,
                     status_callback_t callback,
                     int force_flag,
                     int create_joinable_thread,
                     const char *partition)
{
    printf(" test in install from url  \n");
    install_thread_args_t *args_p;
    pthread_attr_t attr;
    struct sched_param sched;
    printf(" test before install_thread\n"); ---------------This
printf statement is printing
   /* Prohibit if previous install is still in progress */
   if (install_thread != 0) -----------------------------In this line
its giving sementation exception
    {
    printf(" test install_thread != 0\n"); ---------------Either This
statemet has print
        fail(callback, "install already in progress.");
        return -2;
    }

    /* Setup install thread function arguments */
    printf(" test before malloc\n"); --------------- or  This statemet
has print, both not printing /segem exception

    args_p = malloc(sizeof(install_thread_args_t));
    printf(" test after malloc\n");
    if (args_p == NULL)

when i commented below if case context within that code
/* if (install_thread != 0)
    {
    printf(" test install_thread != 0\n");
        fail(callback, "install already in progress.");
        return -2;
    }
*/

problem

int install_from_url(const char *url,
                     status_callback_t callback,
                     int force_flag,
                     int create_joinable_thread,
                     const char *partition)
{
    printf(" test in install from url  \n");
    install_thread_args_t *args_p;
    pthread_attr_t attr;
    struct sched_param sched;
    printf(" test before install_thread\n");
        /* Prohibit if previous install is still in progress */
/*    if (install_thread != 0)
    {
    printf(" test install_thread != 0\n");
        fail(callback, "install already in progress.");
        return -2;
    }
*/
    /* Setup install thread function arguments */
    printf(" test before malloc\n");
    args_p = malloc(sizeof(install_thread_args_t));
    printf(" test after malloc\n");
    if (args_p == NULL)
    {
    printf(" test args_p == NULL\n");
        syslog(LOG_ERR, "malloc for install thread args failed: %m");
        fail(callback, "System error: out of memory.");
        return -1;
    }
    printf(" test malloc args_p->url\n");
    args_p->url = malloc(strlen(url) + 1);
    if (args_p->url == NULL)
    {
    printf(" test malloc args_p->url == NULL\n");
        syslog(LOG_ERR, "malloc for URL failed: %m");
        fail(callback, "System error: out of memory.");
        free(args_p);
        return -1;
    }
    strcpy(args_p->url, url);
    args_p->image_fd = -1;
    args_p->callback = callback;
    args_p->force_flag = force_flag;
    printf(" test partition\n");
    if (partition != NULL)
    {
    printf(" test in partition  != NULL\n");
        args_p->partition = malloc(strlen(partition) + 1);
    printf(" test malloc args_p->partition\n");
        if (args_p->partition == NULL)
        {
    printf(" test args_p->partition malloc\n");
            syslog(LOG_ERR, "malloc for partition failed: %m");
            fail(callback, "System error: out of memory.");
            free(args_p->url);
            free(args_p);
            return -1;
        }
        strcpy(args_p->partition, partition);
    }
    else
    {
        args_p->partition = NULL;
    }

    printf(" test before pthread_attr_init\n");
    /* Setup install thread attributes */
    pthread_attr_init(&attr);
    if (!create_joinable_thread)
    {
    printf(" test create_joinable_thread\n");
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    printf(" test create_joinable_thread\n");
    }
    memset(&sched, 0, sizeof(sched));
    sched.sched_priority = 10;
    printf(" test before pthread_attr_setschedparam\n");
    pthread_attr_setschedparam(&attr, &sched);
    printf(" test before pthread_attr_setschedparam\n");
    status(callback, INSTALL_CONNECTING, NULL, NULL);
    printf(" test before thread creat \n");
    if (pthread_create(&install_thread, ---------- here agian i am
getting segmentation exception......
                       &attr,
                       install_thread_function,
                       (void *)args_p) != 0)
    {
        syslog(LOG_ERR, "status thread create failed: %m");
        fail(callback, "system error: thread creation failed.");
        free(args_p->partition);
        free(args_p);
        return -1;
    }
    else
    {
    printf(" test after thread creat \n");
        return 0;
    }
}

I would like to know whether uClibc is supporting all pthreads functionalities.
Can any one please help me in solving this problem


Thanks & regards
Vikas TM



More information about the uClibc mailing list