Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #145975

Re: Example uses for read-modify-write operations?

Subject Re: Example uses for read-modify-write operations?
Newsgroups comp.lang.c
References <qknvks$rgm$2@solani.org>
From Clifford Heath <no.spam@please.net>
Message-ID <MAMbF.78233$gN2.1096@fx31.iad> (permalink)
Date 2019-09-04 20:44 +1000

Show all headers | View raw


On 4/9/19 7:20 pm, Philipp Klaus Krause wrote:
> While I saw fetch-and-add mentioned a few times as useful, though not as
> powerful as compare-and-swap, hardware and software tend to provide more
> atomic read-modify-write operations.
> 
> Typically (e.g. in C), there are
> 
> fetch-and-add
> fetch-and-subtract
> fetch-and-bitwise-or
> fetch-and-bitwise-xor
> fetch-and-bitwise-and
> fetch-and-increment
> fetch-and-decrement
> 
> That return the previous value before modification. There also are the
> operators that work as read-modify-write (++, --, +=, -=, <<=, >>=, *=,
> /*, %=, &=, |=, ^=) on atomics that instead return the new value.
> 
> Could someone please point me to examples of algorithms that use these?

If the instructions are truly atomic (bus-locked, excluding intervention 
by DMA as well as other CPU cores and their caches) they can be used to 
implement the full spectrum of lock-free parallelisation primitives.

I know this because I've done it :)

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Example uses for read-modify-write operations? Philipp Klaus Krause <pkk@spth.de> - 2019-09-04 11:20 +0200
  Re: Example uses for read-modify-write operations? Clifford Heath <no.spam@please.net> - 2019-09-04 20:44 +1000
    Re: Example uses for read-modify-write operations? Philipp Klaus Krause <pkk@spth.de> - 2019-09-04 13:26 +0200
      Re: Example uses for read-modify-write operations? Clifford Heath <no.spam@please.net> - 2019-09-04 22:13 +1000
        Re: Example uses for read-modify-write operations? Philipp Klaus Krause <pkk@spth.de> - 2019-09-04 14:33 +0200
      Re: Example uses for read-modify-write operations? already5chosen@yahoo.com - 2019-09-04 05:14 -0700
        Re: Example uses for read-modify-write operations? Philipp Klaus Krause <pkk@spth.de> - 2019-09-04 14:35 +0200
        Re: Example uses for read-modify-write operations? mark.bluemel@gmail.com - 2019-09-04 08:24 -0700
          Re: Example uses for read-modify-write operations? already5chosen@yahoo.com - 2019-09-04 08:37 -0700
          Re: Example uses for read-modify-write operations? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-09-04 17:10 +0100
  Re: Example uses for read-modify-write operations? Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-04 14:28 +0200

csiph-web