Qual (is) vantagem (is) o dispatch_sync tem sobre @synchronized?
Vamos dizer que eu quero fazer este código seguro para thread:
- (void) addThing:(id)thing { // Can be called from different threads
[_myArray addObject:thing];
}
O GCD parece ser a maneira preferida de conseguir isso:
- (void) addThing:(id)thing {
dispatch_sync(_myQueue, ^{ // _myQueue is serial.
[_myArray addObject:thing];
});
}
Que vantagem (s) tem sobre o método tradicional?
- (void) addThing:(id)thing {
@synchronized(_myArray) {
[_myArray addObject:thing];
}
}