开发者

How can I create a thread in unix?

How can one create a thread in unix programming?

What is difference b开发者_如何学编程etween forking and threading?

Is threading more useful than forking?


One usually uses POSIX threads or some other technology wrapped by its API. Forking starts new processes, threading splits an existing process into pieces. Threading results in shared global state, which may or may not be useful given the specific circumstances.


  1. pthread_create()

  2. Forking creates two processes, each having a separate thread of control. Creating a thread creates an extra thread of control within a single process.

  3. No - it is generally harder to get threaded applications right than it is to get separate processes right. And by quite a large margin.


Forking creates a copy of the current process, while threads run in the same process and are normally used to calculate something in the background so the application does not appear to be frozen.

As for the usefulness of threads vs. forking, I would go with threads unless you have a specific need for a second process.

As for how to create a thread, I would recommend using the pthreads library. It will work on any UNIX operating system (Linux, BSD, Mac OS X), but is relatively low level. If you want something higher level, check out QThread from QT.


1.In Fork kernel allocated for all resources and memory.

2.In thread split of the process and shared the memory of process

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜