I understand the difference between a process and a thread. And I know the difference between a user thread and a kernel thread.
Question
How do you code any of them in C? All I know in C is how to create POSIX threads, but is this user threads or kernel threads?
Can anyone put some C code samples for a process, user thread and a kernel thread.
Are there any type of threads that I did not include?
The answers to this mostly depends on your operating system. POSIX threads can be implemented as either user threads or kernel threads – it is just an API specification. On any modern Linux system, they are implemented with kernel threads.
In terms of lower-level APIs, the UNIX system call
fork()creates a new process. On Linux, the system callclone()can be used to create a new kernel thread (by passing theCLONE_VMflag) – other operating systems will have other calls to do this. Creation of a user thread will depend entirely on what user threading library you are using.