<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:΢ÈíÑźÚ
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<BR> <BR>
<DIV id=SkyDrivePlaceholder></DIV>
<DIV>> Date: Wed, 4 Jul 2012 08:12:25 -0700<BR>> Subject: Re: Why can not processes switch in atomic context?<BR>> From: dhylands@gmail.com<BR>> To: buyit@live.cn<BR>> CC: mobile.parmenides@gmail.com; kernelnewbies@kernelnewbies.org<BR>> <BR>> Hi,<BR>> <BR>> On Wed, Jul 4, 2012 at 3:44 AM, ß®Ìì ²· <buyit@live.cn> wrote:<BR>> ><BR>> ><BR>> > ÔÚ 2012-7-3£¬22:26£¬"Parmenides" <mobile.parmenides@gmail.com> дµÀ£º<BR>> ><BR>> ...snip...<BR>> >> 1. For the spinlock case, it is easy to get if preemption is allowed<BR>> >> in critical section, the purpose of protection provided by spinlock<BR>> >> can not be achieved readily.<BR>> >><BR>> > i think disable preemption in spinlock is not for safe, it is<BR>> > For efficiency. Spinlock should exit as soon as possible.<BR>> > If tank1 get spinlock and goto sleep for 100 seconds before<BR>> > Release spinlock, task2 which requests the same spinlock<BR>> > Should wait for 100 seconds, for this example, mutex should be used instead of spinlock.<BR>> <BR>> Unless, of course, the interrupt that fired tried to acquire the<BR>> spinlock it preempted, in which case you would have deadlock, even on<BR>> an SMP system, if the same processor happened to be used for both.<BR>> </DIV>
<DIV> </DIV>
<DIV>yes, i think you are right, suppose task1 use spin_lock_irqsave() to get a spinlock, </DIV>
<DIV>then call schedule() to sleep for a long time, the interrupt on this cpu core will be</DIV>
<DIV>enabled by kernel, and if there is an interrupt triggered on the same cpu and </DIV>
<DIV>get the same spinlock, deadlock will happen.</DIV>
<DIV> </DIV>
<DIV><BR> </DIV>                                            </div></body>
</html>