• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to count Atoms
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to count Atoms


  • Subject: Re: How to count Atoms
  • From: Alastair Houghton <email@hidden>
  • Date: Fri, 07 Oct 2016 16:20:21 +0100

On 7 Oct 2016, at 08:19, Gerriet M. Denkmann <email@hidden> wrote:

> So what is the proper way to count something atomicly and undeprecatedly?

<stdatomic.h> or <atomic> is the approved source for this kind of thing.

In C++, you might write

  #include <atomic>

  std::atomic<int> counter;

then you can just do

  ++counter;
  --counter;

as usual, while in C you’d have to write

  #include <stdatomic.h>

  atomic_int counter;

  atomic_fetch_add(&counter, 1);
  atomic_fetch_sub(&counter, 1);

See http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf for the C11 spec (section 7.17 is the part you’re interested in), or http://en.cppreference.com/w/cpp/atomic for C++11 documentation (you could look in the spec also, but personally I find the C++ specification hard to read).

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >How to count Atoms (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Logging in macOS 12
  • Next by Date: Re: Logging in macOS 12
  • Previous by thread: Re: How to count Atoms
  • Next by thread: deleting connections in .xib
  • Index(es):
    • Date
    • Thread