Questions tagged [fibers]

A fiber is a lightweight thread which uses cooperative rather than preemptive multitasking. It is very similar to and often confused with a [coroutine]. Use this tag for questions relating to the [ruby] feature, otherwise prefer to use [coroutine].

A fiber is a lightweight thread which uses cooperative rather than preemptive multitasking. It is very similar to and often confused with a .

In Ruby, fibers are primitives for implementing light weight cooperative concurrency. It appeared in Ruby 1.9.

Related tags

189 questions
225
votes
9 answers

What is the difference between a thread and a fiber?

What is the difference between a thread and a fiber? I've heard of fibers from ruby and I've read heard they're available in other languages, could somebody explain to me in simple terms what is the difference between a thread and a fiber.
tatsuhirosatou
  • 25,149
  • 14
  • 39
  • 40
114
votes
7 answers

Which would be better for concurrent tasks on node.js? Fibers? Web-workers? or Threads?

I stumbled over node.js sometime ago and like it a lot. But soon I found out that it lacked badly the ability to perform CPU-intensive tasks. So, I started googling and got these answers to solve the problem: Fibers, Webworkers and Threads…
Parth Thakkar
  • 5,427
  • 3
  • 25
  • 34
102
votes
2 answers

Why do we need fibers

For Fibers we have got classic example: generating of Fibonacci numbers fib = Fiber.new do x, y = 0, 1 loop do Fiber.yield y x,y = y,x+y end end Why do we need Fibers here? I can rewrite this with just the same Proc (closure,…
fl00r
  • 82,987
  • 33
  • 217
  • 237
18
votes
1 answer

Fibers vs async await

I'm joining a C# project in which the developers are heavily using Fibers. Before this project I haven't even heard of them and previously used async await and Threads and BackgroundWorkers to my multitasking operations. Today I was asking them why…
Alireza Noori
  • 14,961
  • 30
  • 95
  • 179
16
votes
3 answers

Using managed threads and fibers in CLR

Okay, the following link has a warning that the discussion uses unsupported and undocumented apis. Well I'm trying to use the code sample any way. It mostly works. Any ideas about the specific issue below relating to…
Wayne
  • 2,959
  • 3
  • 30
  • 48
14
votes
2 answers

What is the Meteor concurrency model?

I'm writing server-side logic for a Meteor app that has to update in-memory state in response to requests from the client. This application needs strong concurrency guarantees - in particular, I want to be sure that there is only one update executed…
13
votes
3 answers

Why my boost fiber code is deadlocking

I've tried out boost::fibers::barrier and I cannot find out why the following code deadlocks: #include #include #include #include void…
newhouse
  • 1,152
  • 1
  • 10
  • 27
13
votes
3 answers

Can Ruby Fibers be Concurrent?

I'm trying to get some speed up in my program and I've been told that Ruby Fibers are faster than threads and can take advantage of multiple cores. I've looked around, but I just can't find how to actually run different fibers concurrently. With…
Jesse Jashinsky
  • 10,313
  • 6
  • 38
  • 63
12
votes
2 answers

Consequences of Ruby's fiber 4kB stack size

Fibers are a relatively new concept to me. I'm aware that each fiber's stack size is limited to 4kB and I keep reading that I should "beware" of this. What exactly are the real world consequences of this limit? Edit: It seems that this 4kB…
Matty
  • 33,203
  • 13
  • 65
  • 93
11
votes
5 answers

How to Process Items in an Array in Parallel using Ruby (and open-uri)

I am wondering how i can go about opening multiple concurrent connections using open-uri? i THINK I need to use threading or fibers some how but i'm not sure. Example code: def get_doc(url) begin Nokogiri::HTML(open(url).read) rescue…
Mario Zigliotto
  • 8,315
  • 7
  • 52
  • 71
10
votes
2 answers

Implementing a synchronization barrier in Ruby

I'm trying to "replicate" the behaviour of CUDA's __synchtreads() function in Ruby. Specifically, I have a set of N threads that need to execute some code, then all wait on each other at mid-point in execution before continuing with the rest of…
user2398029
  • 6,699
  • 8
  • 48
  • 80
9
votes
1 answer

Fibers over Threads in D

I'm experimenting with threads and Fibers in D and I was wondering if it is possible to run a Fiber on a different CPU as the main thread is running. And if this is not the case then what would be the reason of using Fibers over Threads. (Practical…
Roel Van Nyen
  • 1,279
  • 1
  • 9
  • 19
8
votes
1 answer

What is the point of Fibers in Ruby?

I don't understand how the below: counts = Hash.new(0) File.foreach("testfile") do |line| line.scan(/\w+/) do |word| word = word.downcase counts[word] += 1 end end counts.keys.sort.each {|k| print "#{k}:#{counts[k]} "} Is so much…
Senjai
  • 1,811
  • 3
  • 20
  • 40
8
votes
1 answer

Ways to implement CPU bound tasks in nodejs

I am using nodejs for a web server which decodes the GET params and returns data in some encoded format. The decode/encode are done using the crypto module of nodejs, which seems to be synchronous. While the time taken to serve a single request is…
mdprasadeng
  • 143
  • 1
  • 8
7
votes
2 answers

How does React decide when to flush all the batched updates?

Since React will queue all the setState in event handler to a queue, if there is a large for loop in the event handler, will react wait for the loop? If setState doesn't happen in an event handler, say in componentDidMount, when it will be…
Blake
  • 7,367
  • 19
  • 54
  • 80
1
2 3
12 13