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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:51:14+00:00 2026-06-13T20:51:14+00:00

Possible Duplicate: pthread Function from a Class I am fairly new to c++ and

  • 0

Possible Duplicate:
pthread Function from a Class

I am fairly new to c++ and I am doing a project regarding TCP.

I need to create a thread so I googled and found this.
http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html

I follow its syntax but encounter errors:
argument of type ‘void* (ns3::TcpSocketBase::)()’ does not match ‘void* ()(void)’

codes:

tcp-socket-base.h:
class TcpSocketBase : public TcpSocket
{
 public:
 ...
 void *threadfunction();
 ....
}




tcp-socket-base.cc:

void
*TcpSocketBase::threadfunction()
{
//do something
}



..//the thread was create and the function is called here
pthread_t t1;
int temp  =  pthread_create(&t1, NULL, ReceivedSpecialAck, NULL); //The error happens here
return;
...

Any help would be appreciated. Thanks!

EDIT:

I took the advise and make the threadfunction a non member function.

namespaceXXX{

void *threadfunction()


int result  =  pthread_create(&t1, NULL, threadfunction, NULL);
      NS_LOG_LOGIC ("TcpSocketBase " << this << " Create Thread returned result: " << result );

void *threadfunction()
{
 .....
}


}

But I got this error instead:

initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* ()(void), void*)’ [-fpermissive]

  • 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-13T20:51:15+00:00Added an answer on June 13, 2026 at 8:51 pm

    If you’d like to continue using pthreads, a simple example is:

    #include <cstdio>
    #include <string>
    #include <iostream>
    
    #include <pthread.h>
    
    void* print(void* data)
    {
        std::cout << *((std::string*)data) << "\n";
        return NULL; // We could return data here if we wanted to
    }
    
    int main()
    {
        std::string message = "Hello, pthreads!";
        pthread_t threadHandle;
        pthread_create(&threadHandle, NULL, &print, &message);
        // Wait for the thread to finish, then exit
        pthread_join(threadHandle, NULL);
        return 0;
    }
    

    A better alternative, if you’re able to, is to use the new C++11 thread library. It’s a simpler, RAII interface that uses templates so that you can pass any function to a thread, including class member functions (see this thread).

    Then, the above exmaple simplifies to this:

    #include <cstdio>
    #include <string>
    #include <iostream>
    
    #include <thread>
    
    void print(std::string message)
    {
        std::cout << message << "\n";
    }
    
    int main()
    {
        std::string message = "Hello, C++11 threads!";
        std::thread t(&print, message);
        t.join();
        return 0;
    }
    

    Note how you can just pass data directly in – casts to and from void* are not needed.

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

Sidebar

Related Questions

Possible Duplicate: pthread Function from a Class I am trying to create a thread
Possible Duplicate: pthread Function from a Class I am getting an error (Can not
Possible Duplicate: pthread Function from a Class I have this code that I can't
Possible Duplicate: c++ multithread I use c++ to implement a thread class. The code
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: The thread create by pthread_create the same with the kernel thread? I
Possible Duplicate: Create an empty object in JavaScript with {} or new Object()? When
Possible Duplicate: kill thread in pthread Here after a source code containing a launch
Possible Duplicate: Can main function call itself in C++? I found this problem very

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.