Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3631110
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:21:20+00:00 2026-05-19T00:21:20+00:00

I am porting a mid-sized body of C++ code to Android NDK. Unfortunately the

  • 0

I am porting a mid-sized body of C++ code to Android NDK. Unfortunately the pthreads implementation (as of NDK v5, anyway) is incomplete. Specifically, our application relies on pthread_cancel() to kill a worker thread. NDK does not implement pthread_cancel()! There are other obvious answers when the worker thread is responding normally. But in cases where the worker thread is not responding (e.g. infinite loop), how can I cancel it without killing the whole process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:21:21+00:00Added an answer on May 19, 2026 at 12:21 am

    Possible option that works for this guy: http://igourd.blogspot.com/2009/05/work-around-on-pthreadcancel-for.html

    Reposting here in case:

    Then I use pthread_kill to trigger a
    SIG_USR1 signal and use signal handler
    to exit this pthread and tried it, it
    works, but still wondering if any
    drawbacks for this kind of method.

    Timer out:

    if ( (status = pthread_kill(pthread_id, SIGUSR1)) != 0) 
    { 
        printf("Error cancelling thread %d, error = %d (%s)", pthread_id, status, strerror status));
    } 
    

    USR1 handler:

    struct sigaction actions;
    memset(&actions, 0, sizeof(actions)); 
    sigemptyset(&actions.sa_mask);
    actions.sa_flags = 0; 
    actions.sa_handler = thread_exit_handler;
    rc = sigaction(SIGUSR1,&actions,NULL);
    void thread_exit_handler(int sig)
    { 
        printf("this signal is %d \n", sig);
        pthread_exit(0);
    }
    

    Looks like the best answer is to rewrite so that threads aren’t waiting on IO: http://groups.google.com/group/android-platform/browse_thread/thread/0aad393da2da65b1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am porting some existing C code to run on Android. This C code
I'm porting a native library to a NDK application. When I try to use
Porting a pure Flash/AS3 application to Flex 4.5 this code: <fx:Script> <![CDATA[ import mx.events.SliderEvent;
Currently porting an iPhone application to Android. I've encountered an issue that I haven't
Porting an application from C# (1.1 framework) to VB.NET (3.5 framework), and I have
Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr);
While porting an application from SQL 2005 to SQL Server Compact Edition, I found
While porting a desktop application to windows mobile I've reached the following error: Error
I'm working on porting a Visual C++ application to GCC (should build on MingW
I'm porting old VB6 code that uses the Winsock control to C#. I haven't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.