Swift 3 在GCD的语法上改变了很多,更加贴近了swift的语法,而且关于队列的优先级也改变了不少。
原先的GCD只有四个优先级,high,default,low,background
然而现在的GCD有六个优先级,background,utility,default,userInitiated,userInteractive,unspecified
经过试验,得出了几个结论,
userInteractive的优先级最高,相当于high
background的优先级最低,相当于原来的background
default的优先级高于unspecified,userInitiated,utility
unspecified的优先级高于userInitiated,utility
userInitiated的优先级高于utility
userInteractive>default>unspecified>userInitiated>utility>background
另附实验代码,若有不正确的地方欢迎指正
for i in 1...10 { dispatchQueue.global(qos: dispatchQoS.QoSClass.default).async { NSLog("dispatchQoS.QoSClass.default,%d",i) } dispatchQueue.global(qos: dispatchQoS.QoSClass.background).async { NSLog("dispatchQoS.QoSClass.background,i) } dispatchQueue.global(qos: dispatchQoS.QoSClass.unspecified).async { NSLog("dispatchQoS.QoSClass.unspecified,i) } dispatchQueue.global(qos: dispatchQoS.QoSClass.userInitiated).async { NSLog("dispatchQoS.QoSClass.userInitiated,i) } dispatchQueue.global(qos: dispatchQoS.QoSClass.userInteractive).async { NSLog("dispatchQoS.QoSClass.userInteractive,i) } dispatchQueue.global(qos: dispatchQoS.QoSClass.utility).async { NSLog("dispatchQoS.QoSClass.utility,i) } }
试验数据:
2016-11-15 11:46:12.927070 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInteractive,1 2016-11-15 11:46:12.927363 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInteractive,2 2016-11-15 11:46:12.927407 GraphicsContext[2099:635171] dispatchQoS.QoSClass.userInteractive,3 2016-11-15 11:46:12.927490 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInteractive,4 2016-11-15 11:46:12.927674 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInteractive,5 2016-11-15 11:46:12.927780 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInteractive,6 2016-11-15 11:46:12.927868 GraphicsContext[2099:635172] dispatchQoS.QoSClass.userInteractive,7 2016-11-15 11:46:12.927871 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInteractive,8 2016-11-15 11:46:12.928016 GraphicsContext[2099:635172] dispatchQoS.QoSClass.userInteractive,9 2016-11-15 11:46:12.928138 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInteractive,10 2016-11-15 11:46:12.928719 GraphicsContext[2099:635113] dispatchQoS.QoSClass.default,1 2016-11-15 11:46:12.928817 GraphicsContext[2099:635166] dispatchQoS.QoSClass.unspecified,1 2016-11-15 11:46:12.928924 GraphicsContext[2099:635172] dispatchQoS.QoSClass.userInitiated,1 2016-11-15 11:46:12.929190 GraphicsContext[2099:635173] dispatchQoS.QoSClass.default,2 2016-11-15 11:46:12.929225 GraphicsContext[2099:635171] dispatchQoS.QoSClass.utility,1 2016-11-15 11:46:12.929723 GraphicsContext[2099:635174] dispatchQoS.QoSClass.unspecified,2 2016-11-15 11:46:12.930104 GraphicsContext[2099:635176] dispatchQoS.QoSClass.userInitiated,2 2016-11-15 11:46:12.930131 GraphicsContext[2099:635175] dispatchQoS.QoSClass.utility,2 2016-11-15 11:46:12.930641 GraphicsContext[2099:635177] dispatchQoS.QoSClass.default,3 2016-11-15 11:46:12.931705 GraphicsContext[2099:635179] dispatchQoS.QoSClass.unspecified,3 2016-11-15 11:46:12.931857 GraphicsContext[2099:635180] dispatchQoS.QoSClass.userInitiated,3 2016-11-15 11:46:12.932196 GraphicsContext[2099:635181] dispatchQoS.QoSClass.default,4 2016-11-15 11:46:12.932277 GraphicsContext[2099:635178] dispatchQoS.QoSClass.utility,3 2016-11-15 11:46:12.932779 GraphicsContext[2099:635183] dispatchQoS.QoSClass.unspecified,4 2016-11-15 11:46:12.932889 GraphicsContext[2099:635182] dispatchQoS.QoSClass.userInitiated,4 2016-11-15 11:46:12.933215 GraphicsContext[2099:635185] dispatchQoS.QoSClass.default,5 2016-11-15 11:46:12.933027 GraphicsContext[2099:635184] dispatchQoS.QoSClass.utility,4 2016-11-15 11:46:12.933423 GraphicsContext[2099:635113] dispatchQoS.QoSClass.unspecified,5 2016-11-15 11:46:12.933586 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInitiated,5 2016-11-15 11:46:12.933709 GraphicsContext[2099:635172] dispatchQoS.QoSClass.default,6 2016-11-15 11:46:12.933831 GraphicsContext[2099:635173] dispatchQoS.QoSClass.unspecified,6 2016-11-15 11:46:12.933976 GraphicsContext[2099:635174] dispatchQoS.QoSClass.userInitiated,6 2016-11-15 11:46:12.934095 GraphicsContext[2099:635176] dispatchQoS.QoSClass.default,7 2016-11-15 11:46:12.934242 GraphicsContext[2099:635177] dispatchQoS.QoSClass.unspecified,7 2016-11-15 11:46:12.934356 GraphicsContext[2099:635179] dispatchQoS.QoSClass.userInitiated,7 2016-11-15 11:46:12.934503 GraphicsContext[2099:635180] dispatchQoS.QoSClass.default,8 2016-11-15 11:46:12.934611 GraphicsContext[2099:635171] dispatchQoS.QoSClass.utility,5 2016-11-15 11:46:12.934701 GraphicsContext[2099:635175] dispatchQoS.QoSClass.utility,6 2016-11-15 11:46:12.937166 GraphicsContext[2099:635186] dispatchQoS.QoSClass.unspecified,8 2016-11-15 11:46:12.937476 GraphicsContext[2099:635188] dispatchQoS.QoSClass.userInitiated,8 2016-11-15 11:46:12.937521 GraphicsContext[2099:635187] dispatchQoS.QoSClass.utility,7 2016-11-15 11:46:12.937682 GraphicsContext[2099:635181] dispatchQoS.QoSClass.default,9 2016-11-15 11:46:12.937868 GraphicsContext[2099:635183] dispatchQoS.QoSClass.unspecified,9 2016-11-15 11:46:12.937987 GraphicsContext[2099:635182] dispatchQoS.QoSClass.userInitiated,9 2016-11-15 11:46:12.938110 GraphicsContext[2099:635185] dispatchQoS.QoSClass.default,10 2016-11-15 11:46:12.938262 GraphicsContext[2099:635113] dispatchQoS.QoSClass.unspecified,10 2016-11-15 11:46:12.938381 GraphicsContext[2099:635166] dispatchQoS.QoSClass.userInitiated,10 2016-11-15 11:46:12.938692 GraphicsContext[2099:635178] dispatchQoS.QoSClass.utility,8 2016-11-15 11:46:12.938837 GraphicsContext[2099:635184] dispatchQoS.QoSClass.utility,9 2016-11-15 11:46:12.941483 GraphicsContext[2099:635174] dispatchQoS.QoSClass.utility,10 2016-11-15 11:46:12.949181 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,1 2016-11-15 11:46:12.949734 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,2 2016-11-15 11:46:12.950257 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,3 2016-11-15 11:46:12.950775 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,4 2016-11-15 11:46:12.951348 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,5 2016-11-15 11:46:12.952512 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,6 2016-11-15 11:46:12.953108 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,7 2016-11-15 11:46:12.953659 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,8 2016-11-15 11:46:12.954176 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,9 2016-11-15 11:46:12.954890 GraphicsContext[2099:635115] dispatchQoS.QoSClass.background,10