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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:20:45+00:00 2026-05-23T03:20:45+00:00

Possible Duplicate: pthread Function from a Class I am getting an error (Can not

  • 0

Possible Duplicate:
pthread Function from a Class

I am getting an error (“Can not convert …..”) and I think the third argument in the pthread_create call is wrong. I know the type of the third argument should be (void*)*(void *) but I am still getting an error.

void ServerManager::Init(){  
     pthread_t thread;
     pthread_create(&thread, NULL, AcceptLoop, (void *)this);
}

I have declared like this and I am trying to call the function below

void* ServerManager::AcceptLoop(void * delegate){

}

Please let me know how to fix this..

Thanks in advance.

  • 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-23T03:20:46+00:00Added an answer on May 23, 2026 at 3:20 am

    To be portable the callback function must use the C ABI;

    extern "C" void* AcceptLoop(void*);
    
    class ServerManager 
    {
        public:
           void  Init();
    
        private:
           friend void* AcceptLoop(void*);
    
           void* AcceptLoop();   // Implement this yourself
           pthread_t thread;
    };
    
    void ServerManager::Init()
    {  
         pthread_create(&thread, NULL, &AcceptLoop, reinterpret_cast<void*>(this));
    }
    
    void* AcceptLoop(void* delegate)
    {
        return reinterpret_cast<ServerManager*>(delegate)->AcceptLoop();
    }
    
    void* ServerManager::AcceptLoop()
    {
        // Do stuff
        // Be carefull this may (or may not) start before ServerManager::Init() returns.
        return NULL;
    }
    

    Edit: Based on comment

    pthread_join()

    This will wait for a particular thread to exit. The thread that called pthread_create() can call pthread_join() to wait for the child to finish. A good place for this would(might) be to put the join in the destructor of the ServerManager.

    pthread_cancel()

    pthread_cancel() is an asynchronous request for the thread to stop. The call will return immediately (thus does not mean the thread is dead yet). It is unspecified how quickily it will stop executing your code but it should execute some tidy handlers and then exit. It is a good idea to wait for a cancelled thread using pthread_jon().

    class ServerManager 
    {
        public:
           void  ~ServerManager()
           {
               join();
           }
           void* join()
           {
               void*   result;
               pthread_join(thread, &result);
               return result;
           }
           void cancel()
           {
               pthread_cancel(thread);
               join();
           }
           ... like before
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Difference between Convert.tostring() and .tostring() Hi Carrying on from this question What
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: c++ multithread I use c++ to implement a thread class. The code
Possible Duplicate: or is not valid C++ : why does this code compile ?
Possible Duplicate: Can we change the device time using an application? is that possible
Possible Duplicate: string1 >= string2 not implemented in Linq to SQL, any workarround? To
Possible Duplicate: Updating progress dialog in Activity from AsyncTask I am developing my first

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.