Skip to contentSkip to conversation

sleep for ever ?

DISCUSSION Bo Yang 2 participants 2 messages Sep 6, 2006 – Sep 7, 2006

lore
Share & tools
lore

Bo Yang

author
#0 lore raw

Hi ,
Take a look at following code :

DECLARE_WAITQUEUE(wait, current);

add_wait_queue(q, &wait);

while (!condition) {
        /* if there is an interrupt here , and the interrupt
           is just the one the sleeping process wait
           for , is this process sleep for the interrupt
           for ever ?*/
        set_current_state(TASK_INTERRUPTIBLE);
        if (signal_pending(current))
                /* handle signal */
        schedule();
}

set_current_state(TASK_RUNNING);
remove_wait_queue(q, &wait);

Suppose the process just want to sleep for an hardware event , but before the set_current_state() call , the event come , is the process sleep for ever ?

#1 lore raw

Hello, there.

Quoted 16 lines · Bo Yang

Hi ,
Take a look at following code :

DECLARE_WAITQUEUE(wait, current);

add_wait_queue(q, &wait);

while (!condition) {
        /* if there is an interrupt here , and the interrupt
           is just the one the sleeping process wait
           for , is this process sleep for the interrupt
           for ever ?*/
        set_current_state(TASK_INTERRUPTIBLE);
        if (signal_pending(current))
                /* handle signal */
        schedule();
}
Quoted 6 lines

set_current_state(TASK_RUNNING);
remove_wait_queue(q, &wait);

Suppose the process just want to sleep for an hardware event , but before the set_current_state() call , the event come , is the process sleep for ever ?

I guess you already know it but please try not to post the same message multiple times.

And, yes, you're responsible to set task state *before* testing for the sleeping condition and sleep. In the above code, you can lose the wake up event and thus sleep indefinitely.

Signature · 1 line
tejun