Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a thread in unix?

How can one create a thread in unix programming?

What is difference between forking and threading?

Is threading more useful than forking?

like image 952
bunty Avatar asked Dec 29 '22 07:12

bunty


2 Answers

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.

like image 161
Ignacio Vazquez-Abrams Avatar answered Jan 12 '23 08:01

Ignacio Vazquez-Abrams


  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.

like image 36
Jonathan Leffler Avatar answered Jan 12 '23 06:01

Jonathan Leffler