我正在将一个C++项目移植到iOS上,以便在iPhone和iPad上使用。该项目广泛使用Boost.Coroutine库。Boost.Coroutine没有iPhone的ARMv7 6/ARMv7 7指令集的实现。
- 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中,统一支持协同;我不确定这是否仅限于典型协同行为的一个较小的子集。如果没有,这是否意味着团结有解决办法?
发布于 2012-11-09 01:54:44
您几乎肯定不希望编写程序集指令来执行堆栈操作。iOS已经进入了ARM指令集的第三个版本,已经从ARMv6到ARMv7过渡到了ARMv7s。从iPhone 5开始,苹果公司进一步增加了一个人为的屏障,即你可能不会提交一个也支持完整iPhone 5屏幕的ARMv6分叉应用程序。我确信,苹果的动机是确保在将来的某个时候,它可以在没有ARMv6兼容模式的情况下过渡到处理器,但对我们开发人员来说,这显然意味着不太依赖特定的指令集。
只剩下线了。iOS有一整套完善的线程处理机制,并且有一个线程来公开相关的子集。大中央调度往往是现在使用的正常解决方案,以确保不同的任务可以同时发生,因此吞噬了大多数互联网文档,但低级别的解决方案仍然存在。
显而易见的简单示例,使用NSConditionLock
- (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];
}
}
发布于 2012-11-14 10:43:45
boost.coroutine (来自奥利弗科瓦尔克;上个月来自boost社区的评论)使用支持ARMv6 (ARM Cortext )的boost.context
https://stackoverflow.com/questions/13300868
复制相似问题