#pragma once
#include <Common/Thread.h>
using namespace Dapfor;
class CMyThread : public Dapfor::Common::CThread
{
public:
CMyThread(const std::string& name);
protected:
virtual int Run();
};
CMyThread::CMyThread(const std::string& name) : CThread(name)
{
}
int CMyThread::Run()
{
for(int i = 0; i < 10; ++i)
{
std::cout << GetThreadName() << ": value = " << i << std::endl;
Sleep(100);
}
return 0;
}
...
typedef std::vector<CMyThread*> Threads;
Threads threads;
for(int i = 0; i < 10; ++i)
{
std::string name("Thread ");
name += Dapfor::Common::CLongFormat().Format(i, 0);
CMyThread* thread = new CMyThread(std::string(name));
threads.push_back(thread);
thread->Start();
}
Sleep(5000);
for(Threads::iterator it = threads.begin(); it != threads.end(); ++it)
{
(*it)->Stop();
(*it)->Wait();
delete *it;
}