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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:00:36+00:00 2026-05-26T09:00:36+00:00

The question I have is, what exactly is the format of the pthread_create function

  • 0

The question I have is, what exactly is the format of the pthread_create function and the function it calls, in terms of pointers and such? I can wrap my head around variable pointers, although I need to clarify my knowledge in that area, but function pointers get icky.

I understand the preferred format is

void *threadfunc(void *arg);

int main()
{
    pthread_t threadinfo;
    int samplearg;
    pthread_create(&threadinfo, NULL, threadfunc, &samplearg);
}

However, this generates a compiler warning that threadfunc’s not returning a value, so apparently the * is something about what threadfunc returns, not a characteristic of the function?

I have also seen the function defined as and the pthread_create formatted like such:

void threadfunc(void *arg);

pthread_create(&threadinfo, NULL, (void *)threadfunc, &samplearg);

Which of these two are correct, or are they functionally equivalent? Could someone explain to me the mechanics of pointers to functions and such?

One last question, would it work to, inside a for loop generating multiple threads, initialize an int samplearg for thread unique values then pass it to pthread_create(...)? I understand samplearg would be in scope inside the threadfunc, I’m just checking in case somehow C doesn’t follow typical scope rules–since samplearg is created inside the for() loop and would typically go out of scope after the iteration of the for() loop, and the actual variable itself is being passed not the value. I’d test myself but there might be a point you could enlighten me on, and developing on a remote linux machine is a bit cumbersome for me.

  • 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-26T09:00:37+00:00Added an answer on May 26, 2026 at 9:00 am

    You have not given your version of void *threadfunc(void *arg); but I am guessing that there is no return statement in it. This is why the compiler is warning you. Since the declaration says that it must return a void* you should return a void*. A void* is a pointer to any pointer type. Only void (without the star) does not need a return statement because it is returning nothing.

    Incidentally, the return value will be passed to a pthread_join statement when another thread joins to the thread you are currently starting.

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

Sidebar

Related Questions

The question I have is exactly same in requirement as How to pass mouse
vb.net windows forms question. I've got 3 forms that have exactly the same functions,
I have exactly the same question posted here: http://www.yiiframework.com/forum/index.php?/topic/25763-grab-data-from-many-to-many-middle-table-using-through/ What and how can the
Similar questions have been asked, but nothing exactly like mine, so here goes. We
The responses I've got to this question have solved the problem I had in
No doubt elements of this question have been asked before, but I'm having trouble
I want to show pop up of question with it's options. Each question have
Question I have an application written in Java. It is designed to run on
Question: I have a question that is apparently not answered by this already-asked Bash
Question We have a large number of xml configuration files that we want merged

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.