首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在iOS上实现协同服务

如何在iOS上实现协同服务
EN

Stack Overflow用户
提问于 2012-11-09 01:33:42
回答 2查看 2.7K关注 0票数 3

我正在将一个C++项目移植到iOS上,以便在iPhone和iPad上使用。该项目广泛使用Boost.Coroutine库。Boost.Coroutine没有iPhone的ARMv7 6/ARMv7 7指令集的实现。

  • 还有其他可以在iOS上运行的协同库吗?
  • 如果没有,是否有可能在手臂上记录协同行为?我可以找到几种可能的方法来做到这一点:
代码语言:javascript
运行
复制
- Write assembly instructions directly to perform the stack manipulation.  I am not very well versed in assembly, and I'm worried that the ARM architecture may not include the instructions necessary to copy & paste the stack, or to manually move the stack pointer.
- Write coroutines using something similar to pthreads, or Win32 fibers.  I'm not sure if there's something like this that could be used on iOS.
- Implement coroutines, perhaps even Boost.Coroutine itself, on top of threads.  This seems the most likely to work, but would definitely have performance drawbacks.

注意:在C# on iOS中,统一支持协同;我不确定这是否仅限于典型协同行为的一个较小的子集。如果没有,这是否意味着团结有解决办法?

EN

回答 2

Stack Overflow用户

发布于 2012-11-09 01:54:44

您几乎肯定不希望编写程序集指令来执行堆栈操作。iOS已经进入了ARM指令集的第三个版本,已经从ARMv6到ARMv7过渡到了ARMv7s。从iPhone 5开始,苹果公司进一步增加了一个人为的屏障,即你可能不会提交一个也支持完整iPhone 5屏幕的ARMv6分叉应用程序。我确信,苹果的动机是确保在将来的某个时候,它可以在没有ARMv6兼容模式的情况下过渡到处理器,但对我们开发人员来说,这显然意味着不太依赖特定的指令集。

只剩下线了。iOS有一整套完善的线程处理机制,并且有一个线程来公开相关的子集。大中央调度往往是现在使用的正常解决方案,以确保不同的任务可以同时发生,因此吞噬了大多数互联网文档,但低级别的解决方案仍然存在。

显而易见的简单示例,使用NSConditionLock

代码语言:javascript
运行
复制
- (void)methodOnThread1
{
    while(1)
    {
        [conditionLock lockWhenCondition:kMoreInputAvailable];

        // process whatever is currently in the common access pool

        [conditionLock unlockWithCondition:kWaitingForInput];
    }
}

- (void)methodOnThread2
{
    while(1)
    {
         // do whatever is necessary to produce more input,
         // creating it locally and taking as long as it takes


        [conditionLock lockWhenCondition:kWaitingForInput];

        // push input to common access pool, by whatever means

        [conditionLock unlockWithCondition:kMoreInputAvailable];
    }
}
票数 5
EN

Stack Overflow用户

发布于 2012-11-14 10:43:45

boost.coroutine (来自奥利弗科瓦尔克;上个月来自boost社区的评论)使用支持ARMv6 (ARM Cortext )的boost.context

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13300868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档