-1

I meet this code:

       @synchronized (self.messageQueue) {
        [self.messageQueue insertObject:messageDictionaryRepresentation atIndex:0];
    }

I want to ask for help what this syntax(@synchronized) use for? Thanks.

  • 2
    It creates a mutex (mutual exclusion) lock on a resource. While a resource is locked by a thread, other threads will block if they also execute `@synthronize` using as key the same object or class. See http://stackoverflow.com/a/1215541/412916 for details. – Jano Feb 24 '13 at 12:08
  • Top hit for Google search "synchronized +site:apple.com": http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafety/ThreadSafety.html%23//apple_ref/doc/uid/10000057i-CH8-SW3 – Martin R Feb 24 '13 at 12:09

1 Answers1

0

See Synchronization. You find that is "a convenient way to create mutex locks on the fly in Objective-C code". a related question is What does @synchronized() do?.

Community
  • 1
  • 1
Mihai8
  • 3,113
  • 1
  • 21
  • 31