Runtime error in pthread program

Discussion in 'C' started by idk, May 15, 2011.

  1. idk

    idk New Member

    Joined:
    May 15, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I am trying to run the following simple program which uses multithreading using pthreads. I compile it like: gcc -lpthread programName.c and it compiles fine. However, when I run it gives errors which I have pasted at the bottom of program.


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

    void *thread_routine(void* arg)
    {
    printf("Inside newly created thread \n");
    }

    int main(int argc, char* argv[])
    {
    pthread_t thread_id;
    void *thread_result;
    pthread_create(&thread_id, NULL, thread_routine, NULL);
    printf("Inside main thread \n");
    pthread_join(thread_id, &thread_result);
    }

    -----------------------
    Errors:
    ---------------------

    /2.c: line 4: syntax error near unexpected token `('
    ./2.c: line 4: `void *thread_routine(void* arg)'



    Any help will be appreciated!!
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    http://lmgtfy.com/?q=pthread_create

    If you don't know how to find working examples with Google then multithreaded programming is going to be WAAAAAAAAAAY beyond you. Multithreaded programming done correctly is *A LOT* harder than using Google.
     
  3. idk

    idk New Member

    Joined:
    May 15, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    @xpi0t0s I already figured out what was wrong with that code. People like you are useless and just know how to make sarcastic comments.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    I guess you didn't check the link then. One of the top few items was a working example. Maybe I'm less useless than you think.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice