semaphore/down()/up() question

From: Richard B. Johnson (
Date: Mon Jul 02 2001 - 15:37:16 EST

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;



int __init init_module()

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
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sat Jul 07 2001 - 21:00:10 EST