Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 699105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:20:57+00:00 2026-05-14T03:20:57+00:00

For the functions here: #include <libkern/OSAtomic.h> there are OSAtomic and OSAtomicBarrier versions. However, the

  • 0

For the functions here:

#include <libkern/OSAtomic.h>

there are OSAtomic and OSAtomicBarrier versions.

However, the documentation does not show sample code for:

  1. When is it safe to use just OSAtomic, without the OSAtomicBarrier version
  2. When is it that OSAtomic would be unsafe, but OSAtomicBarrier would be safe.

Can anyone provide explainations + sample codes?

[Random ramblings of “your opinion” without actual code is useless. Readers: please down vote such answers; and vigrously upvote answers with actual code.]

[C/C++ code preferred; Assembly okay too.]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:20:57+00:00Added an answer on May 14, 2026 at 3:20 am

    On Intel and uniprocessor platforms, it doesn’t matter.

    For multiprocessor PPC systems, you should always use the barrier variety of functions, unless the atomic store affects no data other than the atomic variable.

    The following would not be ok:

    data_structure[y].data++;
    OSAtomicIncrement32(y);
    

    You must use a barrier here, because other threads may see data_structure as out of date.

    However, if you are using an atomic variable for some purpose where it stands alone, you may omit the barrier:

    // y is not used to access any other data
    OSAtomicIncrement32(y);
    

    Fine, as long as the value of y does not affect the variable of any shared data structure.

    Essentially, it’s a cache flush. You can always safely use the barrier functions, but in some cases, you may be able to improve performance by not using the barrier functions, such as if y is not used relative to a data structure. There are probably not many cases where you can use the functions without the barrier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You can read about the 64-bit calling convention here . x64 functions are supposed
here is some sample javascript: SomeObjectType = function() { } SomeObjectType.prototype = { field1:
I came across this example here : #include <vector> #include <cstddef> template<typename Tag> class
I would like to learn how to use binding functions. Here is the idea:
Quoting from here , In C, there are two different namespaces of types: a
Really stupid C question. I'm trying to build the source code here so I
I'm not sure if this is even possible, but here goes: I have a
Okay here's the program I have typed up(stdio.h is included also): /* function main
Someone posted a great little function here the other day that separated the full
Here is my function ( updated ): Public Shared Function shortenUrl(ByVal URL As String)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.