使用fork()将应用程序移植到pthread_create() [英] Porting an application with fork() to pthread_create()

查看:184
本文介绍了使用fork()将应用程序移植到pthread_create()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个Linux应用程序移植到iphone上,我想知道我需要做多少重写才能使它成为多线程应用程序而不是多进程应用程序。

I am porting a linux application to the iphone and I would like to know how much re-writing I have to do to make it a multi-threaded application rather than a multi-process application.

另外,如果我只是通过调用另一个线程上的函数来替换分叉代码,我会在执行流程中看似随机的地方获得exec_bad_address ...有谁知道为什么会出现这种情况?

Also, if I simply replace the forked code with a call to the functions on another thread I get exec_bad_address at seemingly random places in my flow of execution... Does anyone know why this may be the case?

谢谢!

推荐答案

这与你的努力完全相同将您的应用程序转换为unix平台上的多线程应用程序。简单地用pthread_create()调用替换分叉代码 - 几乎总是 - 不够。例如,您可能需要重写支持进程间通信的所有代码。假设一个进程分叉另一个进程,然后这两个进程通过管道进行通信。当然,这将不再适用。等等。你明白了。

It is exactly the same effort you would undergo in transitioning your application to a multi-threaded one on a unix platform. Simply replacing the forking code with calls to pthread_create() is - almost always - not enough. For instance, you may need to rewrite all of the code that supports inter-process communication. Say one process forks another, and then the two processes communicate through a pipe. Of course, this will not work anymore. Etc. You get the idea.

顺便说一句,虽然pthreads可以在iOS上完美运行,但我们强烈建议您使用iOS中提供的其他技术。有关其他详细信息,请阅读

By the way, while pthreads are available and perfectly working on iOS, you are strongly encouraged to use other technologies available in iOS. For additional details, please read

并发编程指南

特别是迁移一节远离线程。

in particular the Section called "Migrating Away from Threads".

有关线程的详细信息,请参阅

For details about threading, see

线程编程指南

这篇关于使用fork()将应用程序移植到pthread_create()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆