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.
@synchronized(self) is used to get rid of the self. prefix.
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.
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.
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.
Critical section 2 will be blocked to other threads, as well, since you're synchronizing on the same object (self
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With