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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:27:27+00:00 2026-06-08T22:27:27+00:00

I am trying to write a simple parallel_for using pthreads. Original code is something

  • 0

I am trying to write a simple parallel_for using pthreads.
Original code is something like this.

#ifdef HAVE_TBB
 template<typename Body> static inline
 void parallel_for( const BlockedRange& range, const Body& body )
 {
        tbb::parallel_for(range, body);
 }
#else
 template<typename Body> static inline
 void parallel_for( const BlockedRange& range, const Body& body )
 {      
        body(range); 
 }
#endif

I rewrite for the case TBB does not exist. Here is what I have written. I have problem compiling it. threadFunc gives errors when I write template<typename Body> before it.

In function 'void cv::parallel_for(const cv::BlockedRange&, const Body&)':
error: no matches converting function 'threadFunc' to type 'void* (*)(void*)'
error: candidates are: template<class Body> void* cv::threadFunc(void*)

These are the error messages I get. There must be a simple fix probably. Thanks.

struct MyStruct {
    BlockedRange range;
    Body& body;
};

//template<typename Body>
static void* threadFunc(void *arg) {
    MyStruct<Body> *rangeBody = (MyStruct<Body>*) arg;
    rangeBody->body(rangeBody->range);
}

template<typename Body> static inline
void parallel_for( const BlockedRange& range, const Body& body )
{
    BlockedRange& range1 = BlockedRange(range.begin(), range.end()/2);
    BlockedRange& range2 = BlockedRange(range.end()/2, range.end());

    MyStruct<Body> rangeBody1; 
    rangeBody1.range = range1; 
    rangeBody1.body = body;

    MyStruct<Body> rangeBody2; 
    rangeBody2.range = range2; 
    rangeBody2.body = body;

    pthread_t thread1, thread2;
    pthread_create(&thread1, NULL, threadFunc, (void*) &rangeBody1);
    pthread_create(&thread2, NULL, threadFunc, (void*) &rangeBody2);
    pthread_join( thread1, NULL);
    pthread_join( thread2, NULL);    
}
  • 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-08T22:27:29+00:00Added an answer on June 8, 2026 at 10:27 pm

    If threadFunc is a function template, then you need to specialise it to get a function as required:

    pthread_create(&thread1, NULL, threadFunc<Body>, &rangeBody1);
                                             ^^^^^^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write header file. I can write simple headers like add(int
I trying to write a simple function to call unmanaged code from managed code.
I am trying to write some simple code which will read a text file
I'm trying to write a simple code in Java to connect to a memcache
I am trying to write simple program using ONLY for loop ( if then
I'm trying to write a simple generic parallel code for minimizing a function in
I'm trying to write simple graphic editor using PyGObject and python 3. I need
i'm trying to write simple C openssl client and server. Here is client's code:
I am trying to write a simple Android application using the NDK and C++.
I'm trying to write a simple interactive (using System.in as source) language using antlr,

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.