问题
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