Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mach_port_deallocate(kernel_thread) failed: (os/kern) invalid




On Oct 31, 2004, at 10:43 PM, Matt Watson wrote:

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.
Matt,

Very much appreciated your thoughts on this!. (this issue we discussed before, but after long testing I ran in the problems described in first e-mail of this e-mail thread).

My tests do NOT justify what you are writing here. If I remove the pthread_detach after the pthread_join. I notice that my virtual memory (checking with Activity monitor) is growing.... because doing this pthread_join 2000 times in this manner my program stopped working because no more memory available and virtual memory of my app growed to 4GB. When I added the follwing:

	if (mThread) {
		pthread_detach(mThread);
	}

I need the join so the PTHREAD_CREATE_DETACHED wasn't an option.

I had no more crashes, no more virtual memory leaks and no errors anymore in the console, after testing for a long time.

I haven't read the book that you are recommending, i got the o-reily one. But I will put this book on my christmas shopping list.




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: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: mach_port_deallocate(kernel_thread) failed: (os/kern) invalid (From: Marc Van Olmen <email@hidden>)
 >Re: mach_port_deallocate(kernel_thread) failed: (os/kern) invalid (From: Matt Watson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.