This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Thread destructors
- From: Chris Nimmers <chris at nimseus dot com>
- To: ecos-discuss at sources dot redhat dot com
- Date: Wed, 7 Apr 2004 16:05:25 +0200
- Subject: [ECOS] Thread destructors
Hi,
I have read the suggestions here regarding thread destructors
and from what I understand it is illegal to do stack clean up
in the destructor as it is it running in its own context(?).
I guess that this also means that pParam input to the
destructor is also on the stack and if it would contain the
address to the allocated stack and be freed this would mess
up the memory. Correct?
// Illegal destructor!?
ThreadDestructor(cyg_addrword_t pParam)
{
// Release allocated stack
// pParam contains the stack address
delete [] (cyg_unit8 *)pParam;
}
I have read somewhere the suggestion of using message boxes.
Does this mean that I can can put a message in a message box
with for example the stack address and then let another
thread do the clean up? Will this work as long as the clean-
up thread has a lower priority than the thread exiting?
// Destructor to high priority thread
ThreadDestructor(cyg_addrword_t pParam)
{
// pParam contains handle to message box
cyg_mbox_put(pParam,
cyg_thread_get_stack_base(cyg_thread_self()));
}
// Low priority thread
CleanupThread(cyg_addrword_t pParam)
{
void *stack_base;
while(1) {
// pParam contains handle to message box
stack_base = cyg_mbox_get(pParam);
if(stack_base != NULL)
delete [] stack_base; // Assuming stack was allocated
using new operator
}
}
(CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS needs to be disbled or
delete will do nothing...)
Any light on this matter would be appreciated.
Regards,
Chris Nimmers
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss