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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:14:33+00:00 2026-05-31T13:14:33+00:00

I am trying to create a function that returns an object with certain type.

  • 0

I am trying to create a function that returns an object with certain type. The problem is that create thread does not accept it. Can somebody help me with the following code?

struct thread_args
 {
    Key *k;
    QNode *q;
    uint8_t USED_DIMENSION;
};

QLeafNode *st ;
  struct thread_args Structthread2;
     Structthread1.k=min;
     Structthread1.q=start;
      Structthread1.USED_DIMENSION=4 ;

pthread_create( &thread1, NULL,(void*)&FindLeafNode,  ((void *) &Structthread1));
pthread_join( thread1, (void**)st);

QLeafNode* FindLeafNode (Key *k, QNode * r, uint8_t USED_DIMENSION ){

}
  • 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-31T13:14:33+00:00Added an answer on May 31, 2026 at 1:14 pm

    First off, your thread function is not correctly defined. Only functions of the form:

    void* function_name(void* param)
    

    can be passed to pthread_create.

    Now, in order to return a pointer to something from this function, you need two pthread functions:

    pthread_exit(void *value_ptr);
    

    Call this inside the thread function to return a value through value_ptr and

    pthread_join(pthread_t thread, void **value_ptr);
    

    Call this inside the parent thread to wait for the termination of the child with handle thread and retrieve the value returned by pthread_exit in value_ptr.

    So your code should look something like:

    struct thread_args
     {
        Key *k;
        QNode *q;
        uint8_t USED_DIMENSION;
    };
    
    QLeafNode *st ;
    struct thread_args Structthread1;
    Structthread1.k=min;
    Structthread1.q=start;
    Structthread1.USED_DIMENSION=4 ;
    
    pthread_create(&thread1, NULL, FindLeafNode,  ((void *) &Structthread1));
    pthread_join(thread1, (void**)st);
    
    ...
    
    void* FindLeafNode (void* param) {
        struct thread_args* value = (struct thread_args*) param;
        // use value for computations
        QLeafNode* result = ... // allocate result with new / malloc
        pthread_exit((void*)result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My friend is trying to create a utility function that is given some Type
Is it possible to create a function that returns a generic of unspecified type,
I'm trying to create a function in Groovy that does the following: Accepts 2
I'm trying to create a function that searches up a WebControl's parent-child relationship (basically
I am trying to create a function that will block access to some of
I'm trying to create a function that would dynamically allocate an array, sets the
I am trying to create a function that given a divid, and a list
I'm trying to create a function that will simply allow me to pass an
I am trying to create a function that sends 100 call per second, and
I’m trying to learn Haskell and I was trying to create a function that

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.