Below are the example we used.
class CustomThread
{
public:
CustomThread(const std::wstring &id1)
{
t = new test(id1);
}
~CustomThread();
void startThread() {
std::cout << "Do threading Operation here....." << std::endl;
}
private:
std::wstring id;
test *t;
};
int main()
{
for (int i = 1; i < 100; i++)
{
std::wstring id = L"1";
CustomThread *ct = new CustomThread(id);
boost::thread new_thread;
new_thread = boost::thread(& CustomThread::startThread, ct);
new_thread.detach();
}
// sleep for 100 second - to complete the thread task....
sleep(100);
return 0;
}
I created detachable thread and I want to start 100 detachable thread.
Here we are doing new CustomThread
100 times and allocating memory. Is it automatically deleted once the thread finish the operation?
Can you guide how to free the allocated memory with above example?