semaphore/down()/up() question

Richard B. Johnson (root@chaos.analogic.com)
Mon, 2 Jul 2001 16:37:16 -0400 (EDT)


I need to stop a kernel thread at a certain place in the
driver code. The task that stopped it needs to know that it's
stopped, i.e., needs to wait until it's sleeping.

Later on, I need to start it. So, I thought that a
semaphore would work. It works the first time, but
not after that. In other words, the first down_interruptible()
does, indeed put it in "down_interruptible". I can wake it
up with 'up()'. After that, the kernel thread just ignores
(immediately returns from) down_interruptible().

Trying to find out what was going on, I decided to cheat and
initialize the semaphore immediately before down_interruptible().
Again, it works the first time. However, the second time through
the code then gets stuck in down_interruptible() and a call to
up() gets stuck forever.

Also, it seems that up() and down() are logically reversed,
up() seems to wait until down() is executed. I would expect
that up() would just return if the semaphore was not active,
i.e., locked.

Does anybody know what's going on? Maybe this isn't how to
use these kernel services??

static struct semaphore stopper;

kernel_thread()
{
for(;;)
{
down_interruptible(&stopper);
do_stuff();
}
}

ioctl()
{
up(&stopper);
}

int __init init_module()
{
init_MUTEX_LOCKED(&stopper);
}

Cheers,
Dick Johnson

Penguin : Linux version 2.4.5 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.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/