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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:16:15+00:00 2026-06-12T14:16:15+00:00

In hello world example of pthread it is stated: #include <pthread.h> #include <stdio.h> void

  • 0

In hello world example of pthread it is stated:

#include <pthread.h>
#include <stdio.h>

void * print_hello(void *arg)
{
  printf("Hello world!\n");
  return NULL;
}

int main(int argc, char **argv)
{
  pthread_t thr;
  if(pthread_create(&thr, NULL, &print_hello, NULL))
  {
    printf("Could not create thread\n");
    return -1;
  }

  if(pthread_join(thr, NULL))
  {
    printf("Could not join thread\n");
    return -1;
  }
  return 0;
}

As you can see print_hello in pthread_create() has no argument, however in the definition, it looks like void * print_hello(void *arg)

What does that mean?

Now assume I have this implementation

void * print_hello(int a, void *);
int main(int argc, char **argv)
{
  pthread_t thr;
  int a = 10;
  if(pthread_create(&thr, NULL, &print_hello(a), NULL))
  {
    printf("Could not create thread\n");
    return -1;
  }
  ....
  return 0;
}
void * print_hello(int a, void *arg)
{
  printf("Hello world and %d!\n", a);
  return NULL;
}

Now I get this error:

too few arguments to function print_hello

So how can I fix that?

  • 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-12T14:16:16+00:00Added an answer on June 12, 2026 at 2:16 pm

    pthread passes one argument of type void * to thread function, So you can pass a pointer to any type of data that you want as fourth argument of pthread_create function, look at the example below that fixes your code.

    void * print_hello(void *);
    int main(int argc, char **argv)
    {
        pthread_t thr;
        int a = 10;
        if(pthread_create(&thr, NULL, &print_hello, (void *)&a))
        {
            printf("Could not create thread\n");
            return -1;
        }
        ....
        return 0;
    }
    
    void * print_hello(void *arg)
    {
        int a = (int)*arg;
        printf("Hello world and %d!\n", a);
        return NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

a classic hello world example from their doc, class HelloWorld def call(env) return [200,
Complete C++ i18n gettext() hello world example has C++ code that works for a
Can anyone provide me with a hello world example for a major mode in
Using Complete C++ i18n gettext() hello world example I changed the locale from es_MX
An example of the process/output would be: File1: hello world File2: foo bar Resulting
Suppose I have a example.php file like that: <p> <?php echo _('Hello world') ?>
I want to fit strings into a specific width. Example, Hello world -> ...world,
The XWiki FAQ gives an example for XWiki 1.0 syntax: {graphviz:type=dot}digraph G {Hello->world}{graphviz} My
For the Hello World example in android.com , the package name is package com.example.helloandroid;
I need a Hello World example... [WebService(Namespace = xxxxx)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService()] public

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.