Say I create a pthread as pthread_t lift_3; and pthread_create(&lift_1, NULL, lift, share);. When it goes into lift(), how can I get it the function to print the actual name of the thread? Or set a name for the thread?
I have tried using pthread_self() to acquire the id, but it instead gives random numbers
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void* lift(void* ptr)
{
printf("thread name = %c\n", pthread_self());
pthread_exit(NULL);
return NULL;
}
int main()
{
pthread_t lift_1; // declare thread
pthread_create(&lift_1, NULL, lift, NULL);
pthread_join(lift_1, NULL);
return 0;
}
The expected outcome should be thread name = lift_1