create thred in class code example
Example 1: c++ thread incide class
#include <iostream>
#include <thread>
class foo
{
public:
void make_foo_func_thread()
{
t=std::thread(&foo::foo_func, this);
t.join();
}
private:
std::thread t;
void foo_func() { std::cout << "Hello\n"; }
};
int main()
{
foo f;
f.make_foo_func_thread();
}
Example 2: creating thread in java example
class Multi3 implements Runnable{
public void run(){
System.out.println("thread is running...");
}
public static void main(String args[]){
Multi3 m1=new Multi3();
Thread t1 =new Thread(m1);
t1.start();
}
}