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

  • SEARCH
  • Home
  • 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 4085256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:33:03+00:00 2026-05-20T18:33:03+00:00

I am trying to convert Java code into Objective C code. And the java

  • 0

I am trying to convert Java code into Objective C code. And the java code contains variables defined as volatile. I looked online and “volatile” usage in java as follwing

 Essentially, volatile is used to indicate that a variable's value will be modified by different threads.

So, If I was going to set variables as volatile in Objective C because the variables are going to be accessed by different threads then I don’t need to set those variables as volatile because I can just set those variables as atomic?

  • 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-20T18:33:04+00:00Added an answer on May 20, 2026 at 6:33 pm

    The volatile keyword exists in Objective-C as well. You can use it.

    This is because Objective-C is a superset of C.

    Declaring the properties as atomic will not correct what volatile was meant to do. volatile effectively tells the compiler not to optimize away checks done on that variable, because it may have changed when the compiler expected it to stay the same.

    The simplest example is this. Say we have a global variable declared as:

    int packetsReceived = 0;
    

    And it’s later used like this:

    packetsRecieved = 0;
    
    while (packetsRecieved < 10){
        //Wait for more packets
    }
    
    processPackets();
    

    We will never get through that loop, because the compiler will say “Hey, packetsRecieved is never modified in that loop, therefore it will run infinitely.” As a result, it will just make it a straight infinite loop so it can avoid having to check every time.

    If we instead had declared the variable as:

    volatile int packetsRecieved;
    

    We are telling the compiler that this variable may change at any time, even when it looks like it should stay the same. So in our example, the machine code generated by the compiler will still have a check on the condition, and our program will work as expected.

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

Sidebar

Related Questions

I'm trying to convert to Java some code that uses SDL. I'm using the
I'm trying to convert Morse code into text. I have two text files to
I'm trying to convert old QuickTime framework code to the 64-bit Cocoa-based QTKit on
I'm trying to convert some code that worked great in VB, but I can't
I am trying to convert an ASP.NET website into a web application project. The
I am trying to convert an int into three bytes representing that int (big
I'm trying to convert an incoming sting of 1s and 0s from stdin into
I'm trying to convert an XML file into the markup used by dokuwiki, using
I'm trying to convert a short into 2 bytes...and then from those 2 bytes
What's up y'all, I am trying to write some code in Java that will

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.