Home > Net >  How do i display the attributes of a thread in C?
How do i display the attributes of a thread in C?

Time:01-05

Since pthread_t is a struct, I thought that I could simply get the attributes directly. Checked this page and saw the names of the thread attributes (detachedstate, schedparam etc) so I tried it like this:

pthread_t t1;

void routine() {
    printf(t1.inheritsched);
}

int main(int argc, char **argv) {    
    pthread_create(&t1, NULL, &routine, NULL);
    pthread_join(t1, NULL);
    return 0;
}

But i got an error saying basically that pthread_t isn’t a struct, which surprised me.

What exactly is going on, and how can i display a thread's attributes?

CodePudding user response:

The specification says:

Upon successful completion, pthread_create() shall store the ID of the created thread in the location referenced by thread.

Thus we know that pthread_t is just the ID of the thread, with the exact type not stated in the specification.

  •  Tags:  
  • Related