How to cancel a thread using thread id in C

1 Answer

0 votes
#include <stdio.h>
#include <pthread.h>
  
void *function(void *p) {
    printf("void *function(void *p)\n");
  
    pthread_cancel(pthread_self()); 
      
    return NULL;
}
  
int main()
{
    pthread_t thread;
  
    pthread_create(&thread, NULL, function, NULL); 
  
    pthread_join(thread, NULL); 
  
    return 0;
}
 
 
 
/*
run:
 
void *function(void *p)
 
*/

 



answered May 18, 2018 by avibootz
edited May 29, 2023 by avibootz

Related questions

1 answer 250 views
250 views asked May 18, 2018 by avibootz
1 answer 202 views
202 views asked Feb 6, 2018 by avibootz
1 answer 175 views
175 views asked Jan 29, 2024 by avibootz
1 answer 277 views
1 answer 279 views
1 answer 261 views
261 views asked Jun 30, 2019 by avibootz
...