Re: mutexs for synchronization between kernel threads?

Johannes Erdfelt (jerdfelt@sventech.com)
Wed, 21 Apr 1999 19:40:09 -0400


On Thu, Apr 22, 1999, V Ganesh <ganesh@vxindia.veritas.com> wrote:
> > Well, under 2.2.6 spin_lock and spin_unlock in the non SMP case are
> > NOOPS (do { } while(0)). This is not what I want.
>
> no, this _is_ what you want. remember that on UP, a kernel thread cannot
> thread can be pre-empted unless it voluntarily blocks. this itself
> guarantees mutual exclusion for your threads A and B. that's why spinlocks
> are no-ops in UP.
> what this means is that A and B do not run in "parallel". however,
> interrupts may occur "in parallel" or asynchronous with A and B, so you
> need to protect against them.
> that's why you use spinlock_irqsave and spinlock_irqrestore to protect your
> structures in A and B rather than plain spinlocks. they work out to
> save_flags(flags);cli() and restore_flags(flags) in UP which is exactly
> what you want.

Aha! This makes much more sense. I removed all of the semaphore/mutex
stuff and stuck with the spinlocks.

I still had problems, but only in some circumstances. I tracked it down
to adding a an entry to a list_head twice thus creating a circular
list. The thread was never giving up processor control and eventually
I'd get all kinds of weird oops'.

Thanks very much for clarification. This significantly simplifies
things.

JE

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