Thread: a point of threads to create multiple threads

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    26

    a point of threads to create multiple threads

    Code:
    #include <pthread.h>
    #incldue <stdlib.h>
    #include <cstdio.h>
    #include <calloc.h>
    
    
    void *testing(void *threadid)
    {
            printf("hello");
            pthread_exit(NULL);
    
    }
    
    int main()
    {
            int c=5;
            pthread_t *thread1;
            thread1 = (pthread_t*)calloc(c, sizeof(pthread_t));
            pthread_create(thread1[0], NULL, testing, NULL);
            pthread_create(thread1[1], NULL, testing, NULL);
            pthread_create(thread1[2], NULL, testing, NULL);
            pthread_create(thread1[3], NULL, testing, NULL);
            pthread_create(thread1[4], NULL, testing, NULL);
            return 0;
            int x=0;
            for(x; x<c; x++)
            {
                    pthread_join(thread1[t],NULL);
            }
            return 0;
    }
    i want to run a user specified number of threads however i get the following errors:
    main.cc:9: error: `printf' undeclared (first use this function)
    main.cc:9: error: (Each undeclared identifier is reported only once for each
    function it appears in.)
    main.cc: In function `int main()':
    main.cc:18: error: `calloc' undeclared (first use this function)
    main.cc:19: error: cannot convert `__pthread_st*' to `__pthread_st**' for
    argument `1' to `int pthread_create(__pthread_st**, const pthread_attr_t*,
    void*(*)(void*), void*)'
    main.cc:20: error: cannot convert `__pthread_st*' to `__pthread_st**' for
    argument `1' to `int pthread_create(__pthread_st**, const pthread_attr_t*,
    void*(*)(void*), void*)'
    main.cc:21: error: cannot convert `__pthread_st*' to `__pthread_st**' for
    argument `1' to `int pthread_create(__pthread_st**, const pthread_attr_t*,
    void*(*)(void*), void*)'
    main.cc:22: error: cannot convert `__pthread_st*' to `__pthread_st**' for
    argument `1' to `int pthread_create(__pthread_st**, const pthread_attr_t*,
    void*(*)(void*), void*)'
    main.cc:23: error: cannot convert `__pthread_st*' to `__pthread_st**' for
    argument `1' to `int pthread_create(__pthread_st**, const pthread_attr_t*,
    void*(*)(void*), void*)'
    main.cc:28: error: `t' undeclared (first use this function)
    Last edited by v3dant; 10-06-2004 at 06:50 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Is this a question or a reply?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Why did you call the file main.cc? That indicates that it's a C++ program. Try renaming it to main.c
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    [QUOTE=v3dant]
    Code:
    #incldue <stdlib.h>
    #include <cstdio.h>
    #include <calloc.h>
    #include


    Regards,

    Dave

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  2. Multiple threads, Dos APP, manage windows
    By cbrc00f in forum C Programming
    Replies: 1
    Last Post: 04-15-2003, 06:21 AM
  3. Using multiple threads in REALLY old compilers
    By scooby13q in forum C++ Programming
    Replies: 2
    Last Post: 12-16-2002, 04:31 PM
  4. pthread create and join problems
    By rotis23 in forum C Programming
    Replies: 1
    Last Post: 10-11-2002, 08:41 AM
  5. Replies: 2
    Last Post: 03-05-2002, 05:52 AM