C threads

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

  1. sudu

    sudu New Member

    Joined:
    Sep 1, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I was trying to implement threads in my C code and this is the first time I did this I used

    http://www.opengroup.org/onlinepubs/007908799/xsh/pthread_create.html
    and
    http://www.mit.edu:8001/people/proven/IAP_2000/basic_example.html

    as reference

    but when I compile I get the error

    :/home/shahan/engine_driver.c:43: undefined reference to `pthread_detach'
    collect2: ld returned 1 exit status
    make: *** [engine] Error 1

    I will include the code where I create the thread

    can some one help me on this

    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);
              }
    
    
     

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