linux-mips
[Top] [All Lists]

Re: glibc problem

To: ralf@uni-koblenz.de
Subject: Re: glibc problem
From: Dong Liu <dliu@npiww.com>
Date: Tue, 28 Apr 1998 15:11:31 -0400
Cc: linux@cthulhu.engr.sgi.com
In-reply-to: <19980428013350.27295@uni-koblenz.de>
References: <199804222119.RAA20883@pluto.npiww.com> <19980423050447.63659@uni-koblenz.de> <199804241600.MAA05998@pluto.npiww.com> <199804272337.TAA14149@pluto.npiww.com> <19980428013350.27295@uni-koblenz.de>
Sender: owner-linux@cthulhu.engr.sgi.com
ralf@uni-koblenz.de writes:
 > On Mon, Apr 27, 1998 at 07:37:42PM -0400, Dong Liu wrote:
 > 
 > > Sorry, I didn't install it properly, now my program links, but it
 > > still give segementation fault.
 > 
 > Ok.  I have to admit that I never tested any kind of multithread application.
 > If you could provide the code for the program in question, that'd be
 > helpful.
 > 
 >   Ralf
 > 

How about this

---- create-thread.c----

#include <pthread.h>
#include <stdio.h>

void* new_thread(void* arg)
{
        int i;
        printf("Thread[%s] stack at %x\n",arg, &i);
        for (i = 0; i< 4; i++) {
            printf("Thread[%s] %d\n", arg, i);
            sched_yield();
        }
        return(NULL);
}

#define NUM_OF_THREAD 100
main(int argc, char **argv)

{
        int num = NUM_OF_THREAD;
        pthread_t thread[NUM_OF_THREAD];
        
        char *args[NUM_OF_THREAD];
        int i;
        int last;
        void *status;

        if (argc > 1)
            num = atoi(argv[1]);
        if (num>100)
            num = 100;
        printf("Original thread stack at %x\n", &i);

        for (i = 0 ; i < num; i++) {
            args[i] = (char *)malloc(80);
            sprintf(args[i], "%04d", i);
            if (pthread_create(&thread[i],
                               NULL,
                               new_thread, (void *)args[i])) {
                printf("Error: creating new thread[%d]\n", i);
                break;
            }
        }

        last = i;

        for (i = 0 ; i < last; i++) {
            pthread_join(thread[i], &status);
            printf("thread[%d] return status' address %p\n",i, status);
        }
        printf("%d threads created\n", last);
        exit(0);
}




<Prev in Thread] Current Thread [Next in Thread>