Fiber (computer science)

Fiber (computer science)

In computer science, a fiber is a particularly lightweight thread of execution.

Like threads, fibers share address space; where a distinction exists, it is that fibers use co-operative multitasking while threads use pre-emptive multitasking. Threads often depend on the kernel's thread scheduler to preempt a busy thread and resume another thread; fibers yield themselves to run another fiber while executing. The article on threads contains more on the distinction between threads and fibers.

Fibers and coroutines

Fibers describe essentially the same concept as coroutines. The distinction, if there is any, is that coroutines are a language-level construct, a form of control flow, while fibers are a systems-level construct, viewed as threads that happen not to run concurrently. Priority is contentious; fibers may be viewed as an implementation of coroutines [http://www.flounder.com/fibers.htm A Fiber Class] ] , or as a substrate on which to implement coroutines. [http://msdn.microsoft.com/msdnmag/issues/03/09/CoroutinesinNET/default.aspx Implementing Coroutines for .NET by Wrapping the Unmanaged Fiber API] , Ajai Shankar, MSDN Magazine]

Advantages and disadvantages

Because fibers multitask cooperatively, thread safety is less of an issue than with preemptively scheduled threads, and synchronization constructs including spinlocks and atomic operations are unnecessary when writing fibered code, as they are implicitly synchronized. However, many libraries yield a fiber implicitly as a method of conducting non-blocking I/O; as such, some caution and documentation reading is advised. A disadvantage is that fibers cannot utilise multiprocessor machines without also using preemptive threads; however, an N:M threading model with no more preemptive threads than CPU cores can be more efficient than either pure fibers or pure preemptive threading.

Operating system support

Less support from the operating system is needed for fibers than for threads. They can be implemented in modern Unix systems using the library functions getcontext, setcontext and swapcontext in ucontext.h, as in GNU Portable Threads.

On Microsoft Windows, fibers are created using the ConvertThreadToFiber and CreateFiber calls; a fiber that is currently suspended may be resumed in any thread. Fiber-local storage, analogous to thread-local storage, may be used to create unique copies of variables. [http://msdn2.microsoft.com/en-us/library/ms682661.aspx Fibers] , MSDN Library]

See also

*getcontext/setcontext library routines

References

External links

* [http://www.gnu.org/software/pth/ GNU Portable threads]
* [http://freshmeat.net/projects/libpcl/ Portable Coroutines]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Thread (computer science) — This article is about the concurrency concept. For the multithreading in hardware, see Multithreading (computer architecture). For the form of code consisting entirely of subroutine calls, see Threaded code. For other uses, see Thread… …   Wikipedia

  • Heidelberg University Faculty of Mathematics and Computer Science — Infobox University Faculty name = Faculty of Mathematics and Computer Science native name = Fakultät für Mathematik und Informatik established = 2002 dean = Prof. Dr. R. Rannacher staff = 27 students = 1100 website = http://www.math.uni… …   Wikipedia

  • Fiber (disambiguation) — Fiber or Fibre may mean or refer to: * Fiber, a long strand of material. * Dietary fiber * Optical fiber * Fiber (computer science) * Fiber (mathematics) * Fibre (medical) * Fiber wire …   Wikipedia

  • Replication (computer science) — Replication is the process of sharing information so as to ensure consistency between redundant resources, such as software or hardware components, to improve reliability, fault tolerance, or accessibility. It could be data replication if the… …   Wikipedia

  • Computer network — Computer networks redirects here. For the periodical, see Computer Networks (journal). Datacom redirects here. For other uses, see Datacom (disambiguation). Internet map. The Internet is a global system of interconnected computer networks that… …   Wikipedia

  • Computer networking — is the engineering discipline concerned with communication between computer systems or devices. Networking, routers, routing protocols, and networking over the public Internet have their specifications defined in documents called RFCs. [… …   Wikipedia

  • Computer cluster — Not to be confused with data cluster. A computer cluster is a group of linked computers, working together closely thus in many respects forming a single computer. The components of a cluster are commonly, but not always, connected to each other… …   Wikipedia

  • Computer multitasking — In computing, multitasking is a method where multiple tasks, also known as processes, share common processing resources such as a CPU. In the case of a computer with a single CPU, only one task is said to be running at any point in time, meaning… …   Wikipedia

  • Fiber diffraction — is an important simplification of the general scattering technique in which molecular structure is determined from scattering data (usually of X rays, electrons or neutrons). In fiber diffraction the scattering pattern does not change, as the… …   Wikipedia

  • Fiber-optic communication — An optical fiber junction box. The yellow cables are single mode fibers; the orange and blue cables are multi mode fibers: 50/125 µm OM2 and 50/125 µm OM3 fibers respectively. Fiber optic communication is a method of transmitting information from …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”