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: kernel threads



On Thursday, December 5, 2002, at 09:38 AM, Jim Magee wrote:
On Thursday, December 5, 2002, at 08:04 AM, Michael George wrote:
Looking at the Kernel Programming docs on the ADC site, I've found a page on Creating and Destroying Threads. There it is documented how one can create a thread with the IOThread call: IOCreateThread(), and then kill it with the mach thread calls: thread_terminate(getact_thread( thread_t/IOThread ) ).

Obviously, we need to fix that document on the "killing" side of things.
:)

You really shouldn't asynchronously kill threads - especially kernel threads. You should arrange to have the thread kill itself. The easiest way to do this is to have it return from its initial function. If this isn't convenient for you, you can have the thread call IOExitThread() explicitly (after assuring that all the resources it allocated, and is still responsible for, have been freed).

Well... but I want to be able to asynchronously kill it... What is happening is that this thread will start when our device has been idle for a while. That thread will then do Something, and Something can take quite a while (on the order of several ms). It takes long enough that we don't want this happening in our WorkLoop because it will hold all other workloop tasks up. In our case that holdup would be a Very Bad Thing.

But, if while Something is happening our device becomes active again, we want to stop the thread from doing Something and just exit. There are no resources or anything that the thread has to let go (our design is specifically to allow for this thread's activities to be interrupted at any time), it can just die.

If we set a state variable and check it from within the thread (so we'd know when to call IOExitThread()), we'd have to be constantly checking that variable. A bit of a PITA...

The terminate_thread( thread_act_t ) call is still in the system (at least until 10.2.3, eh? :) so there still exists a way to asynchronously kill a thread, it seems. However, how can I turn my IOThread/thread_t into a thread_act_t?

-Michael
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: kernel threads (From: Jim Magee <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.