On 7 Oct 2016, at 08:19, Gerriet M. Denkmann <g...@mdenkmann.de> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to