deadlock from spinlock waiting..

Saurabh Gadia gadia at usc.edu
Sat Aug 22 15:00:53 UTC 2015


Ohh, lots of typos. Sorry for that.

As per your case task A has the lock and task B will be waiting for the
lock. Firstly as per your contex, I take that you are running uniprocessor
targets. So in CORE_spinlock_Wait routine if the lock is not available and
if no timeout is providedthen its true that this thread will spin
indefinitely until it gets the lock. But main question is how will it get
lock if it disables dispatches and interrupts. I guess your going in right
direction. But while waiting for the lock it performs following things:
from corespinlockwait.c

        for(;;)
        {
            ...
            ...
           _ISR_Enable( level );
       /* An ISR could occur here */

       _Thread_Enable_dispatch();
       /* Another thread could get dispatched here */

       /* Reenter the critical sections so we can attempt the lock again. */
       _Thread_Disable_dispatch();

       _ISR_Disable( level );
        }

  So while waiting task B(write task) gives up the processor periodically
if lock is not available. So this way your read task will get the control
from scheduler after write task relinquishes the CPU. Hope this helps.


Thanks,

Saurabh Gadia

On Sat, Aug 22, 2015 at 7:56 AM, Saurabh Gadia <gadia at usc.edu> wrote:

> Hi Kim,
>
> As per your case task A has the lock and task B will be waiting for the
> lock. Firstly as per your contex, I take that you are running querying
> about uniprocessor targets. So in CORE_spinlock_Wait routine if the lock is
> not available and if provide no timeout for this routing then its true that
> this thread will spin indefinitely until it gets the lock. But main
> question how will it get lock if it disables dispatches and interrupts. I
> guess your going in right direction. But while waiting for the lock it
> performs following things: from corespinlockwait.c
>
>         for(;;)
>         {
>             ...
>             ...
>            _ISR_Enable( level );
>        /* An ISR could occur here */
>
>        _Thread_Enable_dispatch();
>        /* Another thread could get dispatched here */
>
>        /* Reenter the critical sections so we can attempt the lock again.
> */
>        _Thread_Disable_dispatch();
>
>        _ISR_Disable( level );
>         }
>
>   So while waiting it gives up the processor periodically if lock is not
> available. Hope this helps.
>
> Thanks,
>
> Saurabh Gadia
>
> On Fri, Aug 21, 2015 at 11:18 PM, Chan Kim <ckim at etri.re.kr> wrote:
>
>> Hello,
>> This is a very basic question and I guess something's wrong in my
>> understanding.
>> I'm trying to use spinlock but not sure if it's working as I intend to
>> use it for.
>> The _CORE_spinlock_Wait function seems to be disabling interrupt. the
>> code brief say even task dispatch is disabled.
>> Then when task A already has the lock, and task B tries to get the lock,
>> how can task A release it if it is not dispatched?
>> My case right now seems like that. (write task waiting for the lock, but
>> read task has the lock and because interrupt is disabled,  read task cannot
>> process things..)
>> I'm uinsg version 4.10.99.
>> Chan
>> _______________________________________________
>> users mailing list
>> users at rtems.org
>> http://lists.rtems.org/mailman/listinfo/users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20150822/dfc78549/attachment.html>


More information about the users mailing list