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 327 views
327 views asked May 18, 2018 by avibootz
1 answer 291 views
291 views asked Feb 6, 2018 by avibootz
1 answer 269 views
269 views asked Jan 29, 2024 by avibootz
1 answer 380 views
1 answer 353 views
1 answer 339 views
339 views asked Jun 30, 2019 by avibootz
...