Re: How to count Atoms
Re: How to count Atoms
- Subject: Re: How to count Atoms
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Fri, 07 Oct 2016 19:50:46 +0700
> On 7 Oct 2016, at 15:43, Ken Thomases <email@hidden> wrote:
>
> On Oct 7, 2016, at 2:19 AM, Gerriet M. Denkmann <email@hidden> wrote:
>>
>> I need (just for debugging purposes) to count something in a thread safe way.
>> […]
>> 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.
>
> These problems are all because you're using the wrong name.
>
> If you #import <libkern/OSAtomic.h> then you get the declaration of OSAtomicIncrement32() (among other things). Note this is not the name you tried (OSIncrementAtomic). If you use the right name, the compiler warning and linker error will go away.
You are completely right. Following your advice everything works perfectly.
I just typed “OSIncrementAtomic” into Xcode Help and was informed that the proper way to use it is:
SInt32 OSIncrementAtomic(volatile SInt32 *address);
The I tried OSAtomicIncrement32 and was told: “No Results”.
This is slightly irritating (and explains why I was using the wrong name).
Thanks a lot for your help!
Kind regards,
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