pthread_setcanceltype workaround in android

551 Views Asked by At

I am writing code for my first tool which supports multi threading but also I want to make my tool for both Linux & Android , and pthread_cancel can't be used in android so I am trying to make separate header file universal-threading.h in which I will declare pthread_cancel function for android.

So when it will compile on Android then universals-threading.h will be included otherwise not.

I made also a function of pthread_setcancelstate for android Here is snippet

static int pthread_setcancelstate(int state, int *oldstate) {
    sigset_t   new, old;
    int ret;
    sigemptyset (&new);
    sigaddset (&new, SIG_CANCEL_SIGNAL);

    ret = pthread_sigmask(state == PTHREAD_CANCEL_ENABLE ? SIG_BLOCK : SIG_UNBLOCK, &new , &old);
    if(oldstate != NULL)
    {
        *oldstate = sigismember(old,SIG_CANCEL_SIGNAL) == 0 ? PTHREAD_CANCEL_DISABLE : PTHREAD_CANCEL_ENABLE;
    }
    return ret;
}

But now I am confused with pthread_setcanceltype function so it will be very helpful for me if you will give a working code block or snippet of pthread_setcanceltype android version .

In short I want to create a fake pthread_setcanceltype function for android

I am not professional its my first tool and I am also new to threading and pthreads so I hope you will consider this while answering me .

0

There are 0 best solutions below