Mailing Lists: Apple Mailing Lists

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

kernel threads



I am trying to fire off a (very) simple kernel thread from my kernel extension.

At first, I thought I'd read in the Apple Docs that pthreads were a good way to do that, but I cannot find that reference. As a matter of fact, what I find now are that the pthreads are for applications, not for the kernel.

So, on to the IOThread and mach thread facilities.

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 ) ).

There is the expected caveat that when killing a thread you must be very careful not to leave any of its timers running and you must lock the thread first.

So, we can create this thread with:
IOThread IOCreateThread( IOThreadFunc, void* );
and we have. That works fine.

Now to kill that thread from another thread (an essential part of what we want to do), the docs say we *may* be able to terminate it with:
kern_return_t thread_terminate(getact_thread(thread_t thread));

thread_terminate( thread_act_t ) we can find, but getact_thread( thread_t ) doesn't seem to be defined in the system (10.2.2).

There are no timers associated with the thread, so I don't have to worry about that. To be safe, I'll happily lock the thread with:
act_lock_thread(thread_act_t)
and then kill it with:
thread_terminate( thread_act_t )

but the problem is that IOCreateThread gives me an IOThread, which is a thread_t. I cannot find anything like the getact_thread( thread_t ) mentioned in the docs.

Strangely, there are MANY routines which will operate on a thread_act_t, but I cannot find out how to generate a thread_act_t. Even if I create the thread with the mach thread call:
thread_t kernel_thread( task_t, void (*)(void) )
(which I don't want to do because I want the argument that IOCreateThread() allows me), I will *still* get a thread_t, not a thread_act_t.

So, after looking at all this for a few hours, I'm baffled. All I want to do is to be able to start a (trivial) thread with an argument and then be able to terminate that thread from another thread. And this is all done within the kernel, so the pthreads interface is out.

There *has* to be a way to do this... Can anyone point me in the right direction?

Thanks!
-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.



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.