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

  • SEARCH
  • Home
  • 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 7919125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:45:25+00:00 2026-06-03T15:45:25+00:00

I used Eclispse Indigo + CDT 8.0.2 + cygwin to develope a multi-thread systerm,

  • 0

I used Eclispse Indigo + CDT 8.0.2 + cygwin to develope a multi-thread systerm, the code is below:

pthread_mutex_t mutexCmd = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t signalCmd = PTHREAD_COND_INITIALIZER;

void * Func(void * arg)
{
    int iStatus;
    while (1)
    {
        int a = 1;
        pthread_cleanup_push(pthread_mutex_unlock, &mutexCmd);
        pthread_mutex_lock(&mutexCmd);
        iStatus = pthread_cond_wait(&signalCmd, &mutexCmd);
        if (iStatus) {
                err_abort(iStatus, "signalCmd status error");
        }
        if(arg->Cmd != navi_Go) //Just a command tag;
        {
            pthread_mutex_unlock(&(pNaviCtrl->mutexCmd));
            continue;
        }
        //do some work
        //.....
        pthread_mutex_unlock(&mutexCmd);
        pthread_cleanup_pop(1);
    }
//pthread_detach(pthread_self());
return  NULL;
}

int main()
{
    int iStatus = 0;
    pthread = tid;
     iStatus = pthread_create(&tid;NULL, Func, NULL);
     if(iStatus)
    {
    err_abort(iStatus, "Start pthread error");
    }
    // do some work
    ...
    //Cancel thread
   void * retval;
   iStatus = pthread_cancel(tid) 
   iStatus = pthread_join(tid; &retval);
   if(iStatus){
        err_abort(iStatus,"Stop thread error");
    }
    return iStatus;
}

where program run, it stop at “iStatus = pthread_join(tid1; &retval);” couldn’t go forward anymore, I think the thread could be happed to deadlock, but can’t find the reason. I supposed after call pthread_cancel(), the thread will exit and return to the pthread_join(),
who can tell me what’s wrong with my code?

  • 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-06-03T15:45:27+00:00Added an answer on June 3, 2026 at 3:45 pm

    Don’t put cleanup_push and _pop inside the while loop. Don’t call them more than once. If you look at them, they are macros that wrap the code between them in { }. They setup a longjump that is used when you call pthread_cancel.

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

Sidebar

Related Questions

System & Environment Windows 7 (64 bit) MinGW 4.6.1 Eclipse Indigo (Not really used
I have downloaded the zxing Google QR code from SVN and used eclipse to
I have problem with installation of PyDev in Eclipse Indigo. I used Help ->
I created a web service with eclipse indigo, tomcat 7 and i used the
I used Eclipse to build a pretty simple Java project. It builds and runs
Has anybody used Eclipse memory manager to detect memory leak in java codes? Can
I have two Java interfaces and one implementing class. (I have used Eclipse to
My attempt to customize the method contains of ArrayList, I used Eclipse to generate
The JTree implementation / Renderer used in eclipse (see the navigation pane on the
What is the version of Eclipse that can be used to draw the UML

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.