Reputation: 1
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
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