I am aware that the C++ standard in its present form does not say
anything about threads, however I do have a relevant question.
I am working on Windows XP/VC++ 8.0.
Is there a problem new'ing a bunch of objects from one thread and
deleting them in another? I do something like:
struct GenericPointerD eleter
{
template<typena me T>
void operator()(T* p)
{
if (ptr != 0)
{
delete ptr;
ptr = 0;
}
}
};
typedef vector<classofp ointers*> vecptrs;
int main()
{
vecptrs myptrs;
CreateThread(.. .... (LPVOID)&myptrs ........);
// use some platform specific API to wait until
threadcallbackr outine terminates
pseudo_wait_for _terminate(thre adcallbackrouti ne);
for_each(myptrs .begin(), myptrs.end(), GenericPointerD eleter());
}
DWORD WINAPI threadcallbackr outine(LPVOID param)
{
vecptrs* my_ptrs = static_cast<vec ptrs*>(param);
my_ptrs->push_back(ne w classofpointers ());
return 0;
}
I have vastly simplified what is essentially happening in my
application...
Should I be careful about new'ing and deleting from the same thread?
anything about threads, however I do have a relevant question.
I am working on Windows XP/VC++ 8.0.
Is there a problem new'ing a bunch of objects from one thread and
deleting them in another? I do something like:
struct GenericPointerD eleter
{
template<typena me T>
void operator()(T* p)
{
if (ptr != 0)
{
delete ptr;
ptr = 0;
}
}
};
typedef vector<classofp ointers*> vecptrs;
int main()
{
vecptrs myptrs;
CreateThread(.. .... (LPVOID)&myptrs ........);
// use some platform specific API to wait until
threadcallbackr outine terminates
pseudo_wait_for _terminate(thre adcallbackrouti ne);
for_each(myptrs .begin(), myptrs.end(), GenericPointerD eleter());
}
DWORD WINAPI threadcallbackr outine(LPVOID param)
{
vecptrs* my_ptrs = static_cast<vec ptrs*>(param);
my_ptrs->push_back(ne w classofpointers ());
return 0;
}
I have vastly simplified what is essentially happening in my
application...
Should I be careful about new'ing and deleting from the same thread?
Comment