Re: mach_port_deallocate(kernel_thread) failed: (os/kern) invalid
Re: mach_port_deallocate(kernel_thread) failed: (os/kern) invalid
- Subject: Re: mach_port_deallocate(kernel_thread) failed: (os/kern) invalid
- From: Marc Van Olmen <email@hidden>
- Date: Fri, 5 Nov 2004 17:35:18 -0500
Matt and Paul
Just want to give an update on this so this e-mail thread is up to date
for people that read the archives:
You were right that deallocating a thread is mutually exclusive:
Create it detached
Detach it
Join in.
Because there is no difference in my application in virtual memory
increasing:
When i call
pthread_join(mThread);
pthread_detach(mThread);
or just call
pthread_join(mThread);
I had one bug that was giving me different results and after a week of
testing i can confirm your thoughts. I still have the fact that when i
use pthread_join that my virtual memory is increasing. I know for a
fact that I myself don't leak any memory because all my memory calls
are done by my own framework and they verify when a pointer is not
released. The virtual memory increasing (or the pthread_join) is not
something that happens a lot in my application, because my application
runs most of the time 24/7 and never need to stop.
regards,
mvo
On Oct 31, 2004, at 10:43 PM, Matt Watson wrote:
On Oct 31, 2004, at 5:40 PM, Marc Van Olmen wrote:
This problem was related to the fact that I called pthread_detach at
the end of the feeder thread routine. Also I was waiting with
pthread_join until the thread was finished. So if I called the
pthread_detach after the pthread_join everything was fine and also
all the resources were deleted.
Then the real problem was that you were calling pthread_join on a
(potentially) non-existent thread. You want to either pthread_detach,
or pthread_join, not both. Both of these will reclaim the thread's
resources, with pthread_join providing a rudimentary synchronization
mechanism. Also, your fix still has a bug, since now you're calling
pthread_detach on a non-existent thread.
Also, if you know you're going to detach the thread, and don't need
the join synchronization, you should just create it with the
PTHREAD_CREATE_DETACHED attribute and avoid calling pthread_detached.
These and other pthreads concepts are explained in any good pthreads
reference. I usually recommend David Butenhof's
_Programming_with_POSIX(R)_Threads_:
http://www.awprofessional.com/title/0201633922
matt.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden