Creates a method by which a thread invokes a class member function.

Source: Internet
Author: User

When a class member function creates a thread to invoke another function of a class member, there are two ways to fix it.

The first kind is more troublesome,
For example, there is a class
void* Gstartvod (void* pvoid);
Class record{
Friend void* Gstartvod (void* pvoid);

void Create_pthread_fun (void* pvoid);
void* thread (void* pvoid);
static record *_record;

PTHREAD_ID _threadid;

}
void*
Gsavevideodata (void* pvoid)
{
Record::_record->thread (PVOID);
}
void Record::create_pthread_fun (void* pvoid)
{
Pthread_create (&_threadid, NULL, GSaveVideoData2, pvoid);

}

Set a static pointer variable for the class itself in the class. Defines a global function. For example, to implement a call to a class member.

The second method is simpler, declaring the called Class member function as a static variable.
Class record{
Friend void* Gstartvod (void* pvoid);

void Create_pthread_fun (void* pvoid);

Static void* thread (void* pvoid);

PTHREAD_ID _threadid;

}
void Record::create_pthread_fun (void* pvoid)
{
Pthread_create (&_threadid, NULL, Thread, pvoid);

}

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.