Porting an application with fork() to pthread_create()

白昼怎懂夜的黑 提交于 2019-12-19 12:24:01

问题


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.

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?

Thanks!


回答1:


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.

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

Concurrency Programming Guide

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

For details about threading, see

Threading Programming Guide



来源:https://stackoverflow.com/questions/6503083/porting-an-application-with-fork-to-pthread-create

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!