A kernel thread is the thread that the kernel is responsible for planning. This means, among other things, that the kernel can schedule each thread on different processors / cores at the same time.
How to use them, a lot depends on the programming languages ββand APIs of the streams, but as a simple illustration
void task_a(); void task_b(); int main() { new_thread(task_a); new_thread(task_b);
In every implementation that I'm familiar with, the kernel can pause them at any time. ("proactive")
User streams, or "User streams", make the program itself responsible for switching between them. There are many ways to do this, and accordingly there are many names for them.
At one end, you have Green Threads; basically trying to do the same thing as kernel threads. Thus, you save all the complexity of programming with real threads.
At the opposite end, you have βFibersβ that must appear before any other fiber is launched. It means
- The fibers are launched sequentially. There are no concurrent performance improvements.
- The interaction between the fibers is very well defined. Another code only works with the exact points you get. Other code will not change variables while working on them.
- Most of the low-complexity issues that programmers face in multithreading, such as cache coherency (looking at MT questions on this site, most people donβt understand this) are not a factor.
As a simple example of fibers, I can think of:
while(tasks_not_done) { do_part_of_a(); do_part_of_b(); }
where everyone does some work and then comes back when that part is done. Note that they run sequentially in the same "hardware thread", which means that you are not getting performance gains from concurrency. On the other hand, the interactions between them are very clearly defined, so you do not have race conditions. The actual operation of each function may vary. They can also be "user thread objects" from some vector / array.
Mahuu
source share