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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:06:57+00:00 2026-05-28T07:06:57+00:00

I have a set of methods that all synchronize to the class object (can’t

  • 0

I have a set of methods that all synchronize to the class object (can’t use self, because multiple instances of this object could be used in multiple threads). Some of those methods call other methods in the class that also synchronize on the class object. Somehow this works and does not cause the deadlock I would expect it to.

I would assume that testA would be blocked from running because testB already has a lock on the class object, but this apparently isn’t the case.

Is it something special that @synchronized is doing or is this a feature of the underlying mutex locks?


Example code that works:

- (NSUInteger)testA
{
    @synchronized(self.class)
    {
        NSLog(@"Doing something in A");
    }
    return 1;
}

- (void)testB
{
    @synchronized(self.class)
    {
        NSLog(@"Doing something in B");
        NSLog(@"A returned: %i", [self testA]);
    }
}

When calling testB the output is:

Doing something in B
Doing something in A
A returned: 1
  • 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-28T07:06:57+00:00Added an answer on May 28, 2026 at 7:06 am

    Mauricio’s comment is correct. From TOCPL:

    The Objective-C synchronization feature supports recursive and reentrant code. A thread can use a single semaphore several times in a recursive manner; other threads are blocked from using it until the thread releases all the locks obtained with it; that is, every @synchronized() block is exited normally or through an exception.

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

Sidebar

Related Questions

I have a class that is stored on the 'server' and multiple clients can
I have a set of extension methods that I regularly use for various UI
I have a set of methods that do some utility work over SQL connection,
I have - class A { // contains certain set() and get() methods }
java.util.Set specifies only methods that return all records (via Iterator or array). Why is
Using VBA i have a set of functions that return an ADODB.Recordset where all
I have a product image class. This is an object with re-use potential for
When I have a method that calls a set of methods that offer strong
I have a method set up that uses jquery form for a file upload
I have a data type that contains a set and a method that expects

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.