a point of threads to create multiple threads

This is a discussion on a point of threads to create multiple threads within the C Programming forums, part of the General Programming Boards category; 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 ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    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, 03: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, 04:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21