Multiplatform multiprocessing?

◇◆丶佛笑我妖孽 提交于 2019-12-31 03:17:37

问题


I was wondering why in the new C++11 they added threads and not processes.

Couldn't have they done a wrapper around platform specific functions?

Any suggestion about the most portable way to do multiprocessing? fork()? OpenMP?


回答1:


If you could use Qt, QProcess class could be an elegant platform independent solution.




回答2:


If you want to do this portably I'd suggest you avoid calling fork() directly and instead write your own library function that can be mapped on to a combination of fork() and exec() on systems where that's available. If you're careful you can make your function have the same or similar semantics as CreateProcess() on Win32.

UNIX systems tend to have a quite different approach to processes and process management compared to Windows based systems so it's non-trivial to make all but the simplest wrappers portable.

Of course if you have C++11 or Boost available I'd just stick with that. If you don't have any globals (which is a good thing generally anyway) and don't set up and shared data any other way then the practical differences between threads and processes on modern systems is slim. All the threads you create can make progress independently of each other in the same way the processes can.

Failing that you could look at An MPI implementation if message passing suits your task, or a batch scheduler system.




回答3:


I am using Boost Interprocess.

It does not provide the possibility to create new processes, but once they are there, it allows them to communicate.

In this particular case I can create the processes I need from a shell script.



来源:https://stackoverflow.com/questions/10602173/multiplatform-multiprocessing

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