The C ++ member function is used as the pthread_create parameter.

Source: Internet
Author: User

It has been said a long time ago that the pointer of C ++ to the class member function is very abnormal. If you want to use the class member function as the parameter of the thread pthread_create, it will be more complicated!

Class {
Public:
Void run (){
}

Static void * run_helper (void * arg ){
(A *) arg)-> run ();
Return (void *) NULL;
}
};

A;
Pthread_t t;
Pthread_create (& t, NULL, & A: run_helper, & );
We wanted to use a. run as the parameter. Therefore, we must create a static run_helper () function and call run (). www.2cto.com in run_helper ().

Related posts:
Programming of TCP/IP exponential growth and linear growth
Function pointer in C ++
C # encapsulate log4net
Use ServletContextListener to create and disable the cache when the server is started and closed
How to Use ServletContextListener
The article you are reading is: C ++ member function as the pthread_create Parameter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.