views:

189

answers:

2

i understand the difference between a process and a thread. and i know the difference between a user thread and a kernel thread.
my question is , 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?

+1  A: 

There's a tutorial that should help with threads. You can use a different attr parameter to pthread_create to choose user vs kernel.

For processes, try the fork tutorial.

John
+1  A: 

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 call clone() can be used to create a new kernel thread (by passing the CLONE_VM flag) - 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.

caf