Re: How to count Atoms
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