linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* wait_event() problems <patch>
@ 2001-07-03 20:17 Richard B. Johnson
  0 siblings, 0 replies; only message in thread
From: Richard B. Johnson @ 2001-07-03 20:17 UTC (permalink / raw)
  To: Linux kernel


I have been trying to get the following to work:

atomic_t stop;
struct wait_queue wait_queue_stuff, another_wait_queue;
  /* Initialized before use with init_wait_queue() */

kernel_thread()
{
    for(;;)
    {
        if(atomic_read(stop))
            interruptible_sleep_on(&wait_queue_stuff);
        do_regular_stuff();
    }
}

ioctl_start()
{
    if(waitqueue_active(&wait_queue_stuff))
    {
        atomic_set(&stop, 0);
        wake_up_interruptible(&wait_queue_stuff);
    }
}
ioctl_stop()
{
    if(!waitqueue_active(&wait_queue_stuff))
    {
        atomic_set(&stop, 1);
        wait_event(another_wait_queue, waitqueue_active(&wait_queue_stuff));
    }
}

The problem is that when ioctl_stop() is executed, the kernel thread
never gets any CPU time so it remains stuck in "D" state forever.

Maybe I'm doing something wrong, but something seems to be broken.
The following patch 'fixes' it.



--- linux-2.4.1/include/linux/sched.h.orig	Tue Jul  3 15:14:07 2001
+++ linux-2.4.1/include/linux/sched.h	Tue Jul  3 15:16:27 2001
@@ -763,6 +763,7 @@
 		set_current_state(TASK_UNINTERRUPTIBLE);		\
 		if (condition)						\
 			break;						\
+                current->policy = SCHED_YIELD;                          \
 		schedule();						\
 	}								\
 	current->state = TASK_RUNNING;					\


Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

    I was going to compile a list of innovations that could be
    attributed to Microsoft. Once I realized that Ctrl-Alt-Del
    was handled in the BIOS, I found that there aren't any.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-07-03 20:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-03 20:17 wait_event() problems <patch> Richard B. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).