public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Robin Farine <acnrf@dial.eunet.ch>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org
Subject: Re: libstdc++/3584: arm-specific atomic operations not atomic
Date: Wed, 11 Jul 2001 10:36:00 -0000	[thread overview]
Message-ID: <20010711173600.29538.qmail@sourceware.cygnus.com> (raw)

The following reply was made to PR libstdc++/3584; it has been noted by GNATS.

From: Robin Farine <acnrf@dial.eunet.ch>
To: Richard.Earnshaw@arm.com
Cc: robin.farine@terminus.org, gcc-gnats@gcc.gnu.org
Subject: Re: libstdc++/3584: arm-specific atomic operations not atomic
Date: 11 Jul 2001 19:34:59 +0200

 Richard Earnshaw <rearnsha@arm.com> writes:
 
 [...]
 
 > The code for this variant would be: 
 >       @ r0 = address (struct {int lock, int value}), r1 = increment.
 >       mov     r2, #INT_MIN
 > 0:
 >       swp     r3, r2, [r0]
 >       cmp     r3, #INT_MIN
 >       beq     0b      @ already locked
 >       @ We now have the lock
 >       ldr     r2, [r0, #4]
 >       add     r2, r2, r1
 >       str     r2, [r0, #4]
 >       str     r3, [r0]        @ Release the lock.
 >       mov     r2
 
 This certainly works correctly but it would introduce another problem. If
 another thread already holds the lock, the current thread would just spin
 hopelessly until the thread that holds the lock gets the CPU and releases
 it. This could result into a dead-lock if the spinning thread has a higher
 priority than the lock owner.
 
 With the swap instruction (in contrast to test-and-set ;-)), I think that such
 routines implementations have to depend on the threading model to explicitly
 release the CPU when they fail to get the lock. Something like:
 
 
         @ r0 = address (struct {int lock, int value}), r1 = increment.
         ...                     @ prolog
         mov     r2, 1
 0:
         swp     r3, r2, [r0]
         teq     r3, #0
         beq     1f              @ got the lock
         mov     lr, pc
         ldr     pc, .thread_yield
         b       0b
 .thread_yield:  .word thread_yield
 
 1:
         @ We now have the lock
         ldr     r2, [r0, #4]
         add     r2, r2, r1
         str     r2, [r0, #4]
         str     r3, [r0]        @ Release the lock.
         mov     r2


             reply	other threads:[~2001-07-11 10:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-11 10:36 Robin Farine [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-10-03  9:17 rearnsha
2002-05-31 18:09 pme
2001-07-12  7:26 Richard Earnshaw
2001-07-12  7:16 Robin Farine
2001-07-11 11:06 Richard Earnshaw
2001-07-11  8:46 Richard Earnshaw
2001-07-06  2:56 robin.farine

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=20010711173600.29538.qmail@sourceware.cygnus.com \
    --to=acnrf@dial.eunet.ch \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).