0

I am compiling an project here is link of project on github

Here is c source code containing pthread_cancel in line 620 and 690 Click here for Source Code

But I am compiling this tool in my android phone and this project containing pthread_cancel function but as we know pthread_cancel is not available in Android libc but pthread_kill is. So my question is that should I use pthread_kill over pthread_canel.

It will be right patch for this project ? Also I want to know all possible problems which can be arised by use of pthread_kill instead of pthread_cancel

And if non of them should be used so then what should I use or do to compile this project on android.

Golu
  • 350
  • 2
  • 14
  • Possible duplicate of [When to use pthread\_cancel and not pthread\_kill](https://stackoverflow.com/questions/3438536/when-to-use-pthread-cancel-and-not-pthread-kill) – Stephen Newell Mar 19 '18 at 03:39
  • 2
    A good choice woul be neither. – Martin James Mar 19 '18 at 04:53
  • If none of them should be used so how can I make this project workable on android – Golu Mar 19 '18 at 06:13
  • 1
    Possible duplicate of [How to kill a child thread in C (Android NDK)?](https://stackoverflow.com/questions/24891552/how-to-kill-a-child-thread-in-c-android-ndk) – n. m. could be an AI Mar 19 '18 at 06:31
  • *If none of them should be used so how can I make this project workable on android* Properly redesign the project. I wouldn't call any code that relies on being able to use `pthread_cancel` "workable". From the [POSIX standard](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html): "The `pthread_cancel()` function shall **request** that `thread` be canceled." Also, see [2.9.5 Thread Cancellation](http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_05), esp. "use of ... return, ... without doing ... results in undefined behavior." et al. – Andrew Henle Mar 19 '18 at 10:11
  • (cont) First, you can't guarantee that a thread can be cancelled. You can only **request** that it be cancelled. And yes, per POSIX if you don't properly handle thread state, simply calling `return` from a function can cause undefined behavior. Read the POSIX standard on thread cancellation - there are many, many ways to invoke undefined behavior if you use `pthread_cancel()`. Anyone using POSIX threads who has the skills to properly use `pthread_cancel()` wouldn't have to ask any questions about it - they'd be writing the answers. – Andrew Henle Mar 19 '18 at 10:18

0 Answers0