是否有一種安全的方法來改變已經在NSOperationQueue中排隊的NSOperation的優先級?如果操作還沒有開始,那麼沒有問題,但是如果它已經在執行,我會得到一個NSInvalidArgumentException。安全的方式來改變一個NSOperation的優先級
5
A
回答
11
你不應該改變NSOperation一旦它已經入隊。根據蘋果的Threading Programming Guide:
重要提示:您永遠不應該修改 操作對象時,它已經經過 添加到隊列中。在等待 隊列時,操作可以在任何時間在 執行。 正在執行時更改其狀態可能會產生不利影響。您可以使用 操作對象的方法來確定 操作是否正在運行,等待 運行,或者已經完成。
+0
更新後的鏈接:http://developer.apple.com/library/mac/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html#//apple_ref/doc/uid/TP40008091 -CH101-SW38 – 2013-06-28 01:11:43
0
在docs上,沒有關於在操作開始後沒有改變優先級的警告,也沒有關於引發異常的提及。
事實上,改變運行操作的優先級根本沒有效果。也許你在別處做錯了什麼?
1
根據Concurrency Programming Guide我們應該能夠更改優先級
For operations added to a queue, execution order is determined first by the
readiness of the queued operations and then by their relative priority.
Readiness is determined by an operation’s dependencies on other operations,
but the priority level is an attribute of the operation object itself.
By default, all new operation objects have a 「normal」 priority, but you
can increase or decrease that priority as needed by calling the object’s
setQueuePriority: method.
相關問題
- 1. 是nice()用來改變線程優先級還是進程優先級?
- 2. 跨平臺的方式來改變java進程優先
- 3. 假裝改變spring autowired的優先級
- 4. 線程安全優先級隊列
- 5. core.match模式的優先級
- 6. 優先級和優先級
- 7. ':last-child'爲什麼改變樣式的優先級?
- 8. 優先級隊列中的優先級
- 9. 變量優先級(節點js中的全局變量)
- 10. 具有兩個優先級的優先級隊列Python
- 11. jQuery更改CSS優先級?
- 12. 更改線程優先級
- 13. 變化進程優先級
- 14. 沒有線程安全性的優先級隊列
- 15. Delphi的線程安全優先級隊列?
- 16. 通過改變方向和優先級尋找多個解決方案
- 17. 通過了解線程的優先級來設置線程的優先級
- 18. MVVM查看優先的方式如何改變視圖
- 19. 在優化,線程安全的方式
- 20. Repast Symphony調度方法優先級和代理優先級
- 21. MySQL的優先級
- 22. ActiveMQ的優先級
- 23. 有什麼方法可以改變兩種賦值方法的優先級嗎?
- 24. 一個正確的方式來編程NSOperation子類取消
- 25. 更改事件的優先級與jQuery
- 26. 如何更改debian的優先級?
- 27. 更改Minix3的優先級隊列
- 28. 線程的延遲優先級更改
- 29. 更改python sys.path的優先級
- 30. 如何更改優先級的進程
你能告訴我們異常的堆棧跟蹤和內容是什麼?目前有點難以診斷 – 2009-07-19 12:57:02