Concurrency
Race conditions
This code gets called from several threads, and count comes out lower than expected. Can you explain why at the CPU level?
final class Stats {
var count = 0
func hit() { count += 1 }
}Race conditions
This code gets called from several threads, and count comes out lower than expected. Can you explain why at the CPU level?
final class Stats {
var count = 0
func hit() { count += 1 }
}ConcurrencyMultiple choiceAdvanced
Five threads each run count += 1 20 times on a shared variable count (initially 0), with …
#race-condition #data-race #lock
Memory and ARCMultiple choiceAdvanced
In Objective-C you declare @property (atomic) int a; and run self.a = self.a + 1 a combin…
#race-condition #lock #atomic
ConcurrencyShort answerAdvanced
In a message list screen, each cell downloads its profile image asynchronously and caches…
#lock #actor
ConcurrencyShort answerBasics
Several image requests read and write the same in-memory cache dictionary at the same tim…
#data-race #actor