我很想嘗試大型中央調度,但我必須開發的是Ubuntu工作站。是libdispatch,和塊擴展到C/OBJ - C等...在Linux上可用?如果是這樣,我怎麼得到它們?Linux上的塊和libdispatch是否可用?
12
A
回答
12
您可能需要使用LLVM Clang (available on Ubuntu)編譯器來獲取塊(目前我認爲這在gcc中沒有,但我一直沒有跟上gcc,所以我可能是錯的。)
正在努力將libdispatch (home for the open source libdispatch)移植到Linux。到目前爲止,大部分努力似乎都在Debian上,但其他一些發行版上也有一些。看到這些討論主題:
6
我已經做了一些工作,取得libdispatch在Linux上工作的OS X山獅版本;結果在Github:http://nickhutchinson.me/libdispatch/。
-2
不是使用塊,而是使用C++ lambda。他們用C++玩的更好,隱藏的魔法也更少。
我不喜歡這樣寫道:
/// Dispatch a function object to a queue.
template<class F>
static void dispatch_async_function(dispatch_queue_t queue, F f) {
struct context_t {
using function_type = F;
context_t(function_type&& f) noexcept
: _f(std::move(f))
{}
static void execute(void* p) noexcept {
auto context = reinterpret_cast<context_t*>(p);
if (context) {
try {
context->_f();
}
catch(...) {
// error processing here
}
delete context;
}
}
private:
function_type _f;
};
dispatch_async_f(queue, new context_t<F>(std::move(f)), &context_t<F>::execute);
}
如果你需要確保一些共享資源所在的呼叫發生(如對象上的回調是由共享指針保持活力)前:
/// Dispatch a function object to a queue. Only execute the function if the tie
/// locks successfully.
template<class F>
static void dispatch_async_tied_function(dispatch_queue_t queue, std::weak_ptr<void> tie, F f) {
struct context_t {
using function_type = F;
context_t(function_type&& f) noexcept
: _f(std::move(f))
{}
static void execute(void* p) noexcept {
auto context = reinterpret_cast<context_t*>(p);
auto lock = _tie.lock();
if (context && tie) {
try {
context->_f();
}
catch(...) {
// error processing here
}
delete context;
}
}
private:
function_type _f;
std::weak_ptr<void> _tie;
};
dispatch_async_f(queue, new context_t<F>(std::move(f)), &context_t<F>::execute);
}
叫他們這樣
dispatch_function(queue, []() { something(); });
或...
dispatch_tied_function(_myQueue, shared_from_this(), [this]() { somethingOnThis(); });
0
使用clang-3.4。
- 命令和apt-get安裝libdispatch-dev的
- 命令和apt-get安裝libblocks運行時-dev的
- 編譯-fblocks
- 鏈接與-lBlocksRuntime -ldispatch
相關問題
- 1. 是否可以在Windows上使用Grand Central Dispatch(`libdispatch`)?
- 2. 在帶有Ansible的Linux上安裝Swift 3 + libdispatch
- 3. 谷歌的Courgette是否可以在Mac和Linux上運行?
- 4. 是否有可能使用Apache在Linux上運行asp?
- 5. 是否可以在Linux上使用CI進行iOS開發?
- 6. 是否可以在Windows和Linux中使用Cocoa開發?
- 7. 是否可以在Linux上更改命名管道的大小?
- 8. 是否有可能讓我的azure functionapp在linux上運行?
- 9. Linux上的ACL是否影響性能
- 10. git子模塊是否合理可用?
- 11. MPS模塊是否可用於Odoo v8?
- 12. 檢查node.js模塊是否可用
- 13. Mono上NetPeerTcpBinding是否可用?
- 14. Linux上apache的mod_jk模塊
- 15. 是否有可能在.NET 3.5上用C#創建VB.net模塊?
- 16. 是否可以在Linux上運行的應用程序中使用Cocoa類
- 17. 是否可以使用$ logProvider來登錄模塊的配置塊?
- 18. 是否有可能使用angular-cli塊和延遲加載scripts.bundle?
- 19. Linux Standard Base(LSB)AppChecker是否可靠?
- 20. 是否可以完全反轉linux?
- 21. 是否可以在Linux上爲asp和asp.net設置一個Web服務器?
- 22. 是否可以在Linux Ubuntu Hardy上安裝ASP?
- 23. 「get_current_user()」函數是否可以在Linux/OSX上運行?
- 24. 是否有可能在Windows上運行linux docker鏡像
- 25. 是否可以在Linux上運行Xamarin Mono?
- 26. 是否可以在Linux(Ubuntu 16.04.1 LTS)上安裝JBoss Fuse 6.3?
- 27. 是否可以在Linux上開發Xamarin項目?
- 28. 是否有可能檢索AppEngine上的一個uri塊?
- 29. 是否可以限制滑塊在滾動條上的距離?
- 30. 是否可以在隱藏的div上啓動尾聲滑塊?
謝謝!許多谷歌搜索只爲我造成混亂。 – mummey 2011-04-13 18:47:49
不客氣!有時候,Google可能很難找到類似這樣的東西,特別是在一個不熟悉的主題上。 – 2011-04-13 21:28:31
只要你可以使用鏗鏘聲,我就可以在ubuntu natty上[很高興地使用gcd](http://chris.mowforth.com/installing-grand-central-dispatch-on-linux)。 – 2011-07-31 10:08:07