C++11 the use of std::thread in member functions of a class

Source: Internet
Author: User
Tags wrapper

#include <thread>#include<iostream>classWrapper { Public:      voidmember1 () {std::cout<<"I am member1"<<Std::endl; }      voidMember2 (Const Char*arg1, unsigned arg2) {Std::cout<<"I am member2 and my first arg is ("<< arg1 <<") and second Arg is ("<< arg2 <<")"<<Std::endl; } std::thread Member1thread () {returnStd::thread (&wrapper::member1, This); } std::thread Member2thread (Const Char*arg1, unsigned arg2) {          returnStd::thread (&wrapper::member2, This, Arg1, arg2); }};intMain () {Wrapper*w =NewWrapper (); Std::thread TW1= w->Member1thread ();  Tw1.join (); W->member2thread ("Hello", -). Detach ();

return 0 ;
}

Join () is the main thread waiting for the child thread's blocking mode

Detach () is the main thread regardless of the non-blocking mode of the child thread

C++11 the use of std::thread in member functions of a class

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.