user3282758
user3282758

Reputation: 1471

Linux and user level threads

How can I create user level threads in Linux. What I understand is that the Pthread library creates kernel level threads. Then how can we create user level threads.

Upvotes: 3

Views: 2194

Answers (1)

oakad
oakad

Reputation: 7585

To implement "green threads" one will need to manipulate the process context to be able to switch between emulated threads of execution. Linux provides a handy API to do so:

Apart from Linux specific (and very flexible) getcontext() and friends, C programming language specifications mandate existence of 2 curious functions, setjmp and longjmp. Those can also be used to implement "green" threads, albeit with somewhat more limited functionality.

Naturally, programming with the aforementioned API is difficult, so libraries were created to simplify the task of "green" thread management (one example being the State Threads library).

Upvotes: 4

Related Questions