multithreading - What is the difference between a thread and a fiber? -


What is the difference between a thread and a fiber? I have heard of fiber from Rabbi and I have heard that they are available in other languages, can someone explain me the simplest terms, that is the difference between thread and fiber.

In most commonly used terms, thread is generally considered prepaid (although it can not always be true based on the operating system), whereas fiber is considered to be light weight, cooperative threads There are different execution paths for your application.

With Threads: Current execution path can be interrupted or preempted at any time (Note: this statement is generalization and always the OS / threading package / etc.). This means that for the thread, data integrity is a big issue because a thread can be stopped between updating a portion of the data, leaving the integrity of the data in a bad or incomplete situation. It also means that the operating system can take advantage of multiple CPUs and CPU cores by running more than one thread at the same time and leaving the developer to protect data access.

With fiber: The current execution path is interrupted only when the fiber yield is executed (as described above). This means that fiber always starts and closes in well defined locations, so data integrity is much less than a problem. In addition, because fiber is often managed in user space, changes in expensive reference switches and CPU state are not needed, due to which there is a need to change from one fiber to another very skilled skill. On the other hand, because any two fibers can run at the same time, using only fibers will not take advantage of many CPUs or multiple CPU cores.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -