How to count Atoms
How to count Atoms
- Subject: How to count Atoms
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Fri, 07 Oct 2016 14:19:24 +0700
I need (just for debugging purposes) to count something in a thread safe way.
This works, but is deprecated:
SInt32 counter;
- (IBAction)doSomething:sender
{
counter = 0;
some loop
{
IncrementAtomic( &counter ); // 'IncrementAtomic' is deprecated: first deprecated in macOS 10.8
....
}
fprintf(stderr, "counter %lld\n", counter); // works ok
}
The deprecation message did not say what to use instead. So I tried OSIncrementAtomic.
Now I get: "Implicit declaration of function 'OSIncrementAtomic' is invalid in C99" and the linker fails, because it does not find it.
#import <libkern/OSAtomic.h> does not help at all.
When I add the Kernel.framework these errors disappear (good), but are only replaced by: “ld: framework not found Kernel” (not so good).
So what is the proper way to count something atomicly and undeprecatedly?
Gerriet.
_______________________________________________
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