let conc = DispatchQueue(label: "test", attributes: .concurrent)
conc.sync {
conc.async {
var x = 1
for n in 1...100000 {
x += n
}
print(2)
}
var x = 1
for n in 1...100000 {
x += n
}
print(3)
}
print(1)
Always print 3, 1, 2
. Why? In my opinion it should print 1, 3, 2
. Because 1
and 3
are at different threads and in this code tasks for 1, 2 and 3
goes simultaneously. Is there only one thread in Playground and in real app it would print 1, 3, 2
? Could somebody explain please.