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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:29:06+00:00 2026-05-28T13:29:06+00:00

Possible Duplicate: Multiple arguments to function called by pthread_create()? How to pass more than

  • 0

Possible Duplicate:
Multiple arguments to function called by pthread_create()?
How to pass more than one value as an argument to a thread in C?

I have these structures:

struct Request {
    char buf[MAXLENREQ];
    char inf[MAXLENREQ]; /* buffer per richiesta INF */
    int lenreq;
    uint16_t port; /* porta server */
    struct in_addr serveraddr; /* ip server sockaddr_in */
    char path[MAXLENPATH];
    /*struct Range range;*/
};

struct RequestGet {
    char buf[MAXLENREQ];
    int maxconnect;
    struct Range range;
};

struct ResponseGet{
    char buf[MAXLENDATA];
    //int LenRange;
    int expire;
    char dati[MAXLENDATA];
    struct Range range; 
};

How can I pass them to pthread_create? No matter about the meanings of each field of structures.

pthread_create(&id,NULL,thread_func,????HERE????);
  • 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-28T13:29:07+00:00Added an answer on May 28, 2026 at 1:29 pm

    You can only pass one parameter, so you generally need to make a function that takes one parameter, even if it just wraps some other calls. You can do this by creating a struct and having the function take a pointer to such a struct.

    A basic example to illustrate the point is below. Please note that it is not a complete example, and should not be used as-is! Note, for example, that none of the memory allocated with malloc() is freed.

    struct RequestWrapper {
        struct Request *request;
        struct RequestGet *request_get;
        struct ResponseGet *response_get;
    };
    
    void thread_func(struct RequestWrapper *rw) {
        // function body here
    }
    
    int main(int argc, char *argv[]) {
        struct Request *request = malloc(sizeof(*request));
        struct RequestGet *request_get = malloc(sizeof(*request_get));
        struct ResponseGet *response_get = malloc(sizeof(*response_get));
        ...
    
        struct RequestWrapper *wrapper = malloc(sizeof(*wrapper));
    
        wrapper->request = request;
        wrapper->request_get = request_get;
        wrapper->response_get = response_get;
    
        ...
    
        pthread_create(&id, NULL, thread_func, &wrapper);
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: thread with multiple parameters How does one thread a sub with two
Possible Duplicate: returning multiple values from a function Suppose i have passed two values
Possible Duplicate: SQL Server: Can I Comma Delimit Multiple Rows Into One Column? I
Possible Duplicate: Multiple forms on ASP.NET page i have a doubt. can we place
Possible Duplicate: Combine multiple results in a subquery into a single comma-separated value Concat
Possible Duplicate: PHP function with unlimited number of parameters How to pass array as
Possible Duplicate: Generic methods and multiple constraints I need a generic function that has
Possible Duplicate: Generate multiple graphics from within an R function Very strange thing happening
Possible Duplicate: Tuple parameter declaration and assignment oddity In Scala, one can do multiple-variable
Possible Duplicate: Multiple Inequalities in Ruby Hi All, I have an ugly logical expression,

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.