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 8234219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:24:16+00:00 2026-06-07T18:24:16+00:00

Need urgent help on thread: the goal here is the separtemask will take each

  • 0

Need urgent help on thread: the goal here is the separtemask will take each image and separate different contours and for each contour in the image it will call handleobject thread. So every for loop will call the handeobject thread. However, object index variable needs to be passed in each thread. But only last value of objectndex is passed, this is becuase the speratemask function loops and repalces the value of obj.objindx and only the last value of obj.objindx is
passed to all the threads. Is there anyway to pass each objectindex
value in handleobject. The code runs fine if we uncomment the pthread_join(tid[objectIndex],NULL); but it will not give a parralel program

void separateMask(IplImage *maskImg)
{    
  for(r = contours; r != NULL; r = r->h_next)
  {
    cvSet(objectMaskImg, cvScalarAll(0), NULL);
    CvScalar externalColor = cvScalarAll(0xff);
    CvScalar holeColor = cvScalarAll(0x00);
    int maxLevel = -1; 
    int thinkness = CV_FILLED; 
    int lineType = 8; /* 8-connected */
    cvDrawContours(objectMaskImg, r, externalColor, holeColor, maxLevel, thinkness,lineType, cvPoint(0,0));;
    obj.objectMaskImg1[objectIndex]=(IplImage *) malloc(sizeof(IplImage));
    obj.objectMaskImg1[objectIndex]=objectMaskImg;
    obj.objindx=objectIndex;
    obj.intensityOut1=intensityOut;
    obj.tasOut1=tasOut;
    pthread_create(&tid[objectIndex],NULL,handleObject,(void *)&obj);
    //pthread_join(tid[objectIndex],NULL);
    printf("objectindx %d\n",obj.objindx);
    objectIndex++;

  }
  // cvReleaseImage(&objectMaskImg);
  //cvReleaseMemStorage(&storage);
  printf("Exitng Separatemask\n");

}


void* handleObject(void *arg)
{
  int i, j;
  handle *hndl;
  hndl=(handle *) malloc(sizeof(handle));
  hndl=(handle*)arg;
  pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
  pthread_mutex_lock(&lock);
  IplImage *pImg;
  float statistics_ratio[3][9];
  pthread_t tid3;
  tas3 tas2;
  pImg = cvLoadImage("image.tif", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
  if(pImg == NULL)
  {
    fprintf(stderr, "Fail to load image %s\n", "tiff file");
    return ;
  }
  tas2.pImg1=pImg;
  printf("tst%d\n",hndl->objindx);
  tas2.x=hndl->objindx;
  tas2.objectMaskImg1=hndl->objectMaskImg1[tas2.x];
  tas2.statistics_ratio[3][9]=statistics_ratio[3][9];
  double mean = average_intensity(pImg, tas2.objectMaskImg1); 
  int total = total_white(pImg, tas2.objectMaskImg1);
  pthread_mutex_unlock(&lock);

  printf("Exiting handle object thread_id %d\n\n", pthread_self());
}
  • 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-07T18:24:17+00:00Added an answer on June 7, 2026 at 6:24 pm

    This function appears to have issues

    void* handleObject(void *arg)
    

    Firstly

        pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
        pthread_mutex_lock(&lock);
    

    this is a locally created mutex – but created WITHIN the thread function. So you lock it but since nothing else can see the mutex, why do you need it??? It gives no synchronization functionality if no other threads can see it.
    Secondly

        float statistics_ratio[3][9];
        pthread_t tid3;
        tas3 tas2;
        pImg = cvLoadImage("image.tif", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
        if(pImg == NULL){
            fprintf(stderr, "Fail to load image %s\n", "tiff file");
            return ;
        }
        tas2.pImg1=pImg;
        printf("tst%d\n",hndl->objindx);
        tas2.x=hndl->objindx;
        tas2.objectMaskImg1=hndl->objectMaskImg1[tas2.x];
        tas2.statistics_ratio[3][9]=statistics_ratio[3][9];
    

    you create a local uninitialised 2d float array statistics_ratio, do nothing with it then assign it to another locally created object member. This appears to be meaningless, as does the declaration of another pthread instance tid3.

    It doesn’t really matter since nothing else can see the thread but you return from inside this function if pImg == NULL without first unlocking the mutex.

    It is very hard to see why your code doesnt work or what it is meant to do, but perhaps the things highlighted above may help. You are creating a lot of local variables within your thread functions which are not being used. I am not sure if you need some of these to be global instead – particularly the mutex (if indeed you need one at all).

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

Sidebar

Related Questions

I am in need of urgent help. I have an application that was working
I need urgent help, after googling a lot since last 3-4 weeks. I only
I need urgent help in this regard. I am trying to run a Python
I'm in urgent need of an Objective-C/Cocoa/Cocoa Touch framework to handle simple charting; pie
Need some regular expressions help. So far I have my code working to allow
Need help, function getFamily() { FB.api('/me/family', function(response) { alert(JSON.stringify(response)); }); } With the above
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need help with a query that I wrote: I have three tables Company id
Basic need is if a record has an Attribute of Urgent, then the attributevalue
This is incredibly urgent, I need to present this application in 3 and a

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.