how pointer another thread?


let's have following category definition:



cthread::cthread ()
{
this->hthread = null;
this->hthreadid = 0;
this->hmainthread = ::getcurrentthread ();
this->hmainthreadid = ::getcurrentthreadid ();
this->timeout = 2000; //milliseconds
}

cthread::~cthread ()
{
//waiting thread terminate
(this->hthread) {
(::waitforsingleobject (this->hthread, this->timeout) == wait_timeout)
::terminatethread (this->hthread, 1);

::closehandle (this->hthread);
}
}

//*********************************************************
//working method
//*********************************************************
unsigned enlarged cthread::process (void* parameter)
{

//a apparatus terminating thread should implemented
//not permitting slight run sure thread
(::getcurrentthreadid () == this->hmainthreadid)
relapse 0;
else {
m_pmypointer = new myclass(...);
// category successfully works here another thread
relapse 0;
}

}

//*********************************************************
//creates thread
//*********************************************************
bool cthread::createthread ()
{

(!this->iscreated ()) {
param* this_param = new param;
this_param->pthread = this;
this->hthread = ::createthread (null, 0, (unsigned enlarged (__stdcall *)(void *))this->runprocess, (void *)(this_param), 0, &this->hthreadid);
relapse this->hthread ? loyal : false;
}
relapse false;

}

//*********************************************************
//creates thread
//*********************************************************
int cthread::runprocess (void* param)
{
cthread* thread;
thread = (cthread*)((param*)param)->pthread;
mislay ((param*)param);
relapse thread->process (0);
}

myclass* cthread::getmypointer() {
relapse m_pmypointer;
}


in sure program, have following:



void main(void) {
cthread thread;
thread.createthread();

myclass* mypointer = thread.getmypointer();
mypointer->somemethod(); // crash, boom, bang!!!!
}


at impulse mypointer used ( sure thread ) crashes. i don't know pointer, points memory, allocated another thread. indeed possible?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?