amit
amit

Reputation: 1

How can we use same thread object multiple times

We want to call start method 4 times but we do not want to create thread object for each time. Is it possible to create one object of thread and call same method 4 times.

we tried different ways but new initialization require for every time when we are calling method.

Upvotes: 0

Views: 24

Answers (1)

Mike Nakis
Mike Nakis

Reputation: 62110

Yes, you can.

First, rename your MyThread::run() to void MyThread::old_run()

Then, write a new MyThread::run() as follows:

void MyThread::run()
{
   for( int i = 0;  i < 4;  i++ )
      old_run();
}

Upvotes: 1

Related Questions