mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Russell King <rmk@arm.linux.org.uk>
To: Nikita Danilov <Nikita@Namesys.COM>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Linux Kernel Mailing List <Linux-Kernel@Vger.Kernel.ORG>
Subject: Re: kernel thread exit race
Date: Wed, 7 Aug 2002 13:12:29 +0100	[thread overview]
Message-ID: <20020807131229.A7327@flint.arm.linux.org.uk> (raw)
In-Reply-To: <15697.1225.84051.277799@laputa.namesys.com>; from Nikita@Namesys.COM on Wed, Aug 07, 2002 at 03:30:17PM +0400

On Wed, Aug 07, 2002 at 03:30:17PM +0400, Nikita Danilov wrote:
> So, complete() is not-arch dependent because spinlocks are "good" in all
> architectures? complete() ends with spin_unlock_irqrestore() so it
> cannot be any better than spinlocks, until there is some hidden magic.

It works like this:

	cpu1					cpu2
kill thread (on cpu2)
					complete_and_exit()
					- takes spinlock
wait_for_completion()
- spins on completion spinlock
					- increments x->done
					- wakes up anyone waiting on
					  the completion
					- releases spinlock
- checks x->done
- decrements x->done
- releases spinlock

OR:

	cpu1					cpu2
kill thread (on cpu2)
wait_for_completion()
- takes spinlock
					complete_and_exit()
					- spins on spinlock
- checks x->done
- adds to waitqueue
- releases spinlock
					- increments x->done
- sleeps
					- wakes up anyone waiting on
					  the completion
- wakes up
- spins on spinlock
					- releases spinlock
- decrements x->done
- releases spinlock

OR:

	cpu1					cpu2
kill thread (on cpu2)
wait_for_completion()
- takes spinlock
- checks x->done
- adds to waitqueue
- releases spinlock
- sleeps
					complete_and_exit()
					- takes spinlock
					- increments x->done
					- wakes up anyone waiting on
					  the completion
- wakes up
- spins on spinlock
					- releases spinlock
- decrements x->done
- releases spinlock

As you can see, wait_for_completion() will never return until complete()
has released the spinlock.

-- 
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html


  reply	other threads:[~2002-08-07 12:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-07  9:22 Nikita Danilov
2002-08-07  9:38 ` Russell King
2002-08-07 11:18 ` Alan Cox
2002-08-07 10:05   ` Nikita Danilov
2002-08-07 12:11     ` Alan Cox
2002-08-07 11:30       ` Nikita Danilov
2002-08-07 12:12         ` Russell King [this message]
2002-08-07 13:22         ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020807131229.A7327@flint.arm.linux.org.uk \
    --to=rmk@arm.linux.org.uk \
    --cc=Linux-Kernel@Vger.Kernel.ORG \
    --cc=Nikita@Namesys.COM \
    --cc=alan@lxorguk.ukuu.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®