World Library  
Flag as Inappropriate
Email this Article

Fiber (computer science)

Article Id: WHEBN0005533712
Reproduction Date:

Title: Fiber (computer science)  
Author: World Heritage Encyclopedia
Language: English
Subject: Parallel computing, Computer multitasking, Thread (computing), Microthread, Setcontext
Collection: Control Flow, Threads (Computing)
Publisher: World Heritage Encyclopedia
Publication
Date:
 

Fiber (computer science)

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

Like threads, fibers share address space. However, 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.

Contents

  • Fibers and coroutines 1
  • Advantages and disadvantages 2
  • Operating system support 3
  • See also 4
  • References 5
  • External links 6

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,[1] or as a substrate on which to implement coroutines.[2]

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 utilize multiprocessor machines without also using preemptive threads; however, an M:N threading model with no more preemptive threads than CPU cores can be more efficient than either pure fibers or pure preemptive threading.

In modern server programs fibers are being used to soft block themselves to allow their one threaded parent programs to continue working. In this design, fibers are being used mostly for i/o access which does not need cpu processing. So, the main program can go on what it is doing. Fibers yield control to the one threaded main program and when related i/o operation event occurred in the operating system like i/o operation has been completed; fibers go on where they left off.

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.[3]

Symbian OS uses a similar concept to fibers in its Active Scheduler. An active object contains one fiber to be executed by the Active Scheduler when one of several outstanding asynchronous calls complete. Several Active objects can be waiting to execute (based on priority) and each one must restrict its own execution time.

See also

References

  1. ^ A Fiber Class
  2. ^ Implementing Coroutines for .NET by Wrapping the Unmanaged Fiber API, Ajai Shankar, MSDN Magazine
  3. ^ Fibers, MSDN Library

External links

  • GNU Portable threads
  • Portable Coroutine Library at Freecode
  • Fiber Pool A multicore-capable C++ framework based on fibers for Microsoft Windows.
  • State Threads
  • Protothreads
  • ribs2
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.