uzyskiwanie błędu w programie „niezdefiniowane odniesienie do gettid”

To jest mój podprogram wątku ... Tutaj tworzę 4 wątki i przekazuję strukturę jako argument do podprogramu wątku.

Próbuję wydrukować identyfikator wątku za pomocągetid() funkcjonować,

Dostaję błąd mówiący„niezdefiniowane odwołanie do gettid ()”.

Dodałem niezbędne pliki nagłówkowe ...

#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#define ARRAYSIZE 17
#define NUMTHREADS 4

struct ThreadData {
        int start, stop;
        int* array; 
};

void* squarer(void* td) 
{
     struct ThreadData* data=(struct ThreadData*) td;

     int start=data->start;
     int stop=data->stop;
     int* array=data->array;
     int i;
     pid_t tid1;

     tid1 = gettid(); //error at this statement//`
     printf("tid : %d\n",tid1);

     for (i=start; i<stop; i++) {
         sleep(1);
         array[i]=i*i;
         printf("arr[%d] = [%d]\n",i,array[i]);
     } 
   return NULL;
}

int main(void) {
    int array[ARRAYSIZE];
    pthread_t thread[NUMTHREADS];
    struct ThreadData data[NUMTHREADS];
    int i;

    int tasksPerThread=(ARRAYSIZE+NUMTHREADS-1)/NUMTHREADS;

    for (i=0; i<NUMTHREADS; i++) {
            data[i].start=i*tasksPerThread;
            data[i].stop=(i+1)*tasksPerThread;
            data[i].array=array;
    }

    data[NUMTHREADS-1].stop=ARRAYSIZE;

    for (i=0; i<NUMTHREADS; i++) {
            pthread_create(&thread[i], NULL, squarer, &data[i]);
    }

    for (i=0; i<NUMTHREADS; i++) {
            pthread_join(thread[i], NULL);
    }

    for (i=0; i<ARRAYSIZE; i++) {
            printf("%d ", array[i]);
    }
    printf("\n");

    return 0;
}

questionAnswers(2)

yourAnswerToTheQuestion