Re: panic in thread_invoke
Re: panic in thread_invoke
- Subject: Re: panic in thread_invoke
- From: Brian Bergstrand <email@hidden>
- Date: Fri, 20 Jun 2003 22:38:00 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Friday, June 20, 2003, at 02:04 AM, Herry Wiputra wrote:
>
Hi,
>
>
I am having a problem with my kext keep panicing in thread_invoke().
>
>
The exact error message is
>
panic: thread_invoke: preemption_level 1
>
>
In my code, I have a function which already hold a network funnel,
>
then enter this while loop in which it will sleep until an event
>
happen
>
and spawn a new thread to handle some computation.
>
>
The new thread will also try to grab the network_funnel and will
>
release it
>
when it returns.
>
>
My kext kept panicing on the second loop, after it spawns a new thread
>
and sleep again waiting for an event to happen.
>
>
Does anyone ever comes across this issue before??
>
Yes. This panic means that you (the thread) is trying to block while
preemption is disabled. This usually means that you are trying to grab
mutex, a semaphore, ore some other type of blocking lock while holding
a spinlock. In your particular case, I would say you are calling an OS
function that blocks from your socket callback function. This is a huge
no-no. In your socket callback function, you cannot block at all. This
means no memory allocation (unless you use kalloc_noblock() and are
willing handle a nil return), no mutexes, semaphores, and no calling
any BSD function since that will likely cause a funnel grab attempt
(which may block). There are probably more of these cases too.
The way I get around this, is to spawn a thread at kext load and have
it wait on a semaphore. Then my socket callback queues incoming sockets
on a list (protected by a spinlock). I then signal the semaphore and
the waiting service thread wakes up and starts pulling sockets off of
the queue.
So basically about the only things that are safe to use in your socket
callback are spinlocks and semaphore signals (but not waits!).
If you have any more questions, let me know.
HTH.
>
Thanks for your help.
>
>
Regards,
>
Herry Wiputra
>
Brian Bergstrand <
http://www.classicalguitar.net/brian/>
PGP Key: <
http://www.classicalguitar.net/brian/misc/public_key.txt>
Egotism is the anesthetic that dulls the pain of stupidity. - Frank
Leahy
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.2
iQA/AwUBPvPFCnnR2Fu2x7aiEQIDDwCdFSsVn33qH6AI9MYBm6CdVKLpauQAoMBh
luEP4OiCs6SOnh5qchxGcct1
=74qv
-----END PGP SIGNATURE-----
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.