C threads

Discussion in 'C' started by sudu, Sep 7, 2006.

Thread Status:
Not open for further replies.
  1. sudu

    sudu New Member

    Joined:
    Sep 1, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I was trying to create threads in my code. This is the first time I tried this I used these as reference
    http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_create.html
    and
    http://www.mit.edu:8001/people/proven/IAP_2000/basic_example.html

    but I always get a error message saying

    engine_driver.o: In function `e_admit_to_engine':/home/shahan/engine_driver.c:39: undefined reference to `pthread_create'
    :/home/shahan/engine_driver.c:43: undefined reference to `pthread_detach'
    collect2: ld returned 1 exit status

    it doesnt recognize the functins

    can any one help me on this??? :confused:

    I enterd the code here (only the part I use threads. I return NULL in engine_ex_comm_write )


    Code:
     
    #include <pthread.h>
    #include "engine.h"
    
    void * engine_ex_comm_read(profile_t *data);
    void * engine_ex_comm_write(profile_t *data);
    int e_admit_engine();
    
    
    int e_admit_to_engine()
    {
    
       profile_t *this_data;
       //extern void * start_routine(void *ths_data);
       //char * this_data1;
       profile_t *new_profile;
       element_t *new_element, *new_element1;
       profile_t * loc;
       int y=0, x, ret;
       pthread_t tid;
       pthread_attr_t attr;
    
       while(1)
       {
          if(y!=is_buffer_emty())
          {
              this_data= read_from_buffer();
    
              if(this_data)
              {
                 engine_ex_comm_write(this_data);
                 if( pthread_create(&tid, NULL, engine_ex_comm_write, this_data))
                 {
                    printf("error creating thread\n");
                 }
                 pthread_detach(tid);
              }
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
Thread Status:
Not open for further replies.

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