Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objective-c : @synchronized, how does it work?

i have two methods

-(void) a {
   @synchronized(self) {
      // critical section 1 
   }
}

-(void) b {
   @synchronized(self) {
      // critical section 2 
   }
}

now my question is if a thread is in critical section 1. will the critical section 2 be locked for other threads or other threads can access critical section 2.

like image 622
g.revolution Avatar asked May 11 '10 12:05

g.revolution


People also ask

What is @synchronized self?

@synchronized(self) is used to get rid of the self. prefix.

Why do we use synchronized IOS?

The presence of multiple threads in an application opens up potential issues regarding safe access to resources from multiple threads of execution. Two threads modifying the same resource might interfere with each other in unintended ways.

What is synchronize in IOS?

Syncing means transferring items and keeping them up to date between your Mac and your iPhone, iPad or iPod touch. For example, when you add a movie to your Mac, you can sync so that the movie appears on both your Mac and iPhone.

What does synchronized mean java?

Synchronization in java is the capability to control the access of multiple threads to any shared resource. In the Multithreading concept, multiple threads try to access the shared resources at a time to produce inconsistent results. The synchronization is necessary for reliable communication between threads.


1 Answers

Critical section 2 will be blocked to other threads, as well, since you're synchronizing on the same object (self).

like image 77
mipadi Avatar answered Sep 17 '22 23:09

mipadi