Last active
June 16, 2020 02:03
-
-
Save scott-lydon/a9a3a3539be9a49ac011758e91cb3995 to your computer and use it in GitHub Desktop.
196 permutations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.main.async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.main.sync(execute: task) | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| ispatchQueue(label: "com.test.mySerialQueue").sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.main.async { | |
| print(2) | |
| synced(self) { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.main.async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| This is when I realized I should try multiple times | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 5 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| The swift compiler has a typing delay after running this. | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.main.sync(execute: task) | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| ispatchQueue(label: "com.test.mySerialQueue").sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 5 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(2) | |
| synced(self) { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.main.async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 5 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 5 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| x3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 2 | |
| 4 | |
| 3 | |
| 5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.main.sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| ispatchQueue(label: "com.test.mySerialQueue").sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(2) | |
| synced(self) { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x2 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.main.async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.main.sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| ispatchQueue(label: "com.test.mySerialQueue").sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(2) | |
| synced(self) { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.main.async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| x3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| x2 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x3 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 2 | |
| 4 | |
| 3 | |
| 5 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| x3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.main.sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| ispatchQueue(label: "com.test.mySerialQueue").sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| x2 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| x3 | |
| OR | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(2) | |
| synced(self) { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| OR | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.main.async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue(label: "com.test.mySerialQueue").async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x6 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x3 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x5 | |
| Notice numbers printing sequentially, not all instantaneous. | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.main.sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| ispatchQueue(label: "com.test.mySerialQueue").sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x5 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .background).async { | |
| print(2) | |
| synced(self) { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| x6 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| DispatchQueue.main.async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 5 | |
| 4 | |
| 3 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 3 | |
| 5 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| DispatchQueue.global(qos: .utility).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 5 | |
| 3 | |
| x2 | |
| OR | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| x2 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| DispatchQueue.global(qos: .userInteractive).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 2 | |
| 4 | |
| 3 | |
| 5 | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| DispatchQueue.global(qos: .background).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| 1 | |
| 5 | |
| 2 | |
| 4 | |
| 3 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| DispatchQueue.main.sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| 1 | |
| 2 | |
| 5 | |
| 3 | |
| 4 | |
| */ | |
| func test() { | |
| print(1) | |
| DispatchQueue.global(qos: .unspecified).async { | |
| print(2) | |
| ispatchQueue(label: "com.test.mySerialQueue").sync { | |
| print(3) | |
| } | |
| print(4) | |
| } | |
| print(5) | |
| } | |
| /* | |
| output: | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| 1 | |
| 5 | |
| 2 | |
| 3 | |
| 4 | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment