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 8389999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:52:20+00:00 2026-06-09T18:52:20+00:00

I have two threads that access the same set of properties, but one only

  • 0

I have two threads that access the same set of properties, but one only reads from the properties, the other one only writes to the properties.

Which of the following properties would need to be synchronized for read operations, and which would have to be synchronized for write operations?

@property (nonatomic) int myInt;
@property (nonatomic) NSInteger myInteger;
@property (nonatomic) CGImageRef cgImage;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) NSMutableArray *array;
@property (nonatomic, strong) UIViewController *controller;

My first instinct is that everything needs to be synchronized for all read and write operations all the time. However, since one thread is always writing and one is always reading, I’m unsure of myself. Sure, always synchronizing is “safe” since I am unsure, but I was wondering what is actually correct?

For some reason, I have this feeling that maybe myInt and myInteger don’t need to be synchronized for reads and writes since they are pass by value….?

  • 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-06-09T18:52:21+00:00Added an answer on June 9, 2026 at 6:52 pm

    well, this is what atomic properties are good at. if they were all atomic, then you could read and write without getting partially written results.

    however, i’ve never found atomic objc properties truly useful in concurrent programs. i always result to regular locking, immutability, and so on.

    although you could use atomics, it just doesn’t get you very much in practical cases. they make your programs more thread resistant (not safe) at execution cost (both are bad, btw).

    btw, pass by value is really not an issue here.

    mutating a mutable value or object (e.g. reading and writing from that NSMutableArray from two threads), and maintaining the integrity of ivars which rely on each other are the primary problems.

    example of maintaining the integrity of two ivars which rely on each other:

    say you have two atomic properties of int type (day,month), and they have accessors. you would need more than atomics to avoid reading an invalid date (e.g. February 31st), if the reads and writes were happening from separate threads. the only way to really ensure your object is not in the middle of a partial update is to use synchronization primitives or immutable data — this is ground atomic properties cannot save you from.

    so the short answer is ‘atomics’, but objects in concurrent contexts are rarely so simple that the middle ground of atomics is truly thread safe.

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

Sidebar

Related Questions

I have an application that has two threads. The first one (the main thread)
I have two threads, one reading streams and producing data-objects from their content. I
I have two threads, one thread processes a queue and the other thread adds
I have two threads: 'main' and 'worker', and one global variable bool isQuitRequested that
I have two threads, a producer thread that places objects into a generic List
I have two threads referencing the same variable -- the UI thread and a
I have two separate websites on the same server. One site is a forum
I've read that "volatile" in Java allows different threads to have access to the
I have two threads modifying the same objects. The objects are custom, non-synchronized objects
Lucene encourages the reuse of an IndexWriter from multiple threads. Given that two threads

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.