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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:12:00+00:00 2026-06-01T14:12:00+00:00

Here is the link to the sample code http://developer.apple.com/library/ios/#samplecode/MVCNetworking/Introduction/Intro.html Below is the code snippet

  • 0

Here is the link to the sample code http://developer.apple.com/library/ios/#samplecode/MVCNetworking/Introduction/Intro.html

Below is the code snippet from the file NetworkManager.m

+ (NetworkManager *)sharedManager
// See comment in header.
{
    static NetworkManager * sNetworkManager;

    // This can be called on any thread, so we synchronise.  We only do this in 
    // the sNetworkManager case because, once sNetworkManager goes non-nil, it can 
    // never go nil again.

    if (sNetworkManager == nil) {
        @synchronized (self) {
            sNetworkManager = [[NetworkManager alloc] init];
            assert(sNetworkManager != nil);
        }
    }
    return sNetworkManager;
}

Obviously there are thread safe issues here. Two NetworkManager instance may be created when there are more than one thread. So Apple made a mistake, right?

  • 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-01T14:12:01+00:00Added an answer on June 1, 2026 at 2:12 pm

    Yes, it’s wrong. Start with sNetworkManager as nil, and consider two threads T1 and T2.

    One possible, if unlikely, scenario is:

    T1: Determines (sNetworkManager == nil) is true
    T2: Determines (sNetworkManager == nil) is true
    T1: Takes the @synchronized lock
        Creates a NetworkManager 
        Sets sNetworkManager
        Releases the lock
    T2: Takes the @synchronized lock
        Creates a NetworkManager 
        Sets sNetworkManager, LEAKING the first one
        Releases the lock
    

    This question has some safer ways of doing it.

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

Sidebar

Related Questions

EDIT: Here's a link to show you my sample code: http://www.singingeels.com/jqtest/ I have a
In this google map sample: http://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html If the user dropped the little guy far
In this google map sample: http://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html If the user dropped the little guy far
here is link to an example: http://techchorus.net/demos/jquery/hiding-input-elements-in-a-div.html It actally disables few elements on click
Here i am again desprately asking for help.. here is the link http://panjtansoft.com/cozeez/products/fdgsd If
here's the sample code (fully working - just copy to an empty html file
I need to create next and previous link urls here's a sample <a href=/calendar/2009/10/>previous</a>
Here is link where i got a code for web-page content fetching. But i
I'm learning by reading this tutorial: Link Here's the code: <?php require_once 'Zend/Loader.php'; class
I am having trouble displaying the jQuery datepicker as shown here: http://jqueryui.com/demos/datepicker/ I believe

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.