I'm trying to use application-managed stacks, i.e. allocating the stack myself and passing it to the pthread creation attributes through pthread_setstack -function. My problem is that the memory allocated for the stack seems to leak after the thread terminates.
Only information I have been able to find about this is in
System Interfaces Chapter 2 section 2.9.8 "Use of Application-Managed Thread Stacks". It states that the application grants to the implementation permanent ownership over the memory region, and that in particular, the region of memory cannot be freed, nor can it be later specified as the stack for another thread.
I've tried to free the stack manually after making sure the thread in question has terminated (by joining to it), which seems to kind of work since the virtual size of the application decreases. However, when I allocate a new stack for a new thread from the heap and the memory previous used for another threads stack is reused, the application crashes at pthread_create.
I'm trying to accomplish (what I'm sure is non-portable) thread stack monitoring by periodically checking the thread stack memory regions for a high water mark. If someone knows another way to do this, I'd be glad to drop the whole application-manager stacks thing.
Has anyone experienced similar problems or alternatively successfully used application-managed stacks?
I'm using NPTL 4.2.
Thanks in advance,
Lasse