fibers

boost::fiber scheduling - when and how

浪尽此生 提交于 2020-05-15 21:46:31
问题 According to the documentation the currently-running fiber retains control until it invokes some operation that passes control to the manager I can think about only one operation - boost::this_fiber::yield which may cause control switch from fiber to fiber. However, when I run something like bf::fiber([](){std::cout << "Bang!" << std::endl;}).detach(); bf::fiber([](){std::cout << "Bung!" << std::endl;}).detach(); I get output like Bang!Bung! \n \n Which means control was passed between <<

cannot compile boost::fiber official examples

扶醉桌前 提交于 2019-12-11 06:19:28
问题 I am trying out boost::fiber library, but I couldn't manage to compile code with boost fiber. Therefore I turned into compiling and running boost official examples. I installed latest version of boost library 1.65.1, and installation seems to be fine. I executed following command to compile simple.cpp g++ -I /usr/local/include/boost/ -L /usr/local/lib/ -lboost_fiber -std=c++11 libs/fiber/examples/simple.cpp But I get the following complains: /tmp/ccWQ5ZMf.o: In function `main': simple.cpp:(

Fibers over Threads in D

99封情书 提交于 2019-12-10 12:47:01
问题 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 examples are very welcome) I tried to write some initial program with Fibers where I switch to the next fiber after some time. Howhever I noticed that the cpu usage stays only on one cpu. The documentation of D states: Please note that there is no

Consequences of Ruby's fiber 4kB stack size

爷,独闯天下 提交于 2019-12-08 15:09:28
问题 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 limitation isn't such a hindrance after all and it takes a good number of local variables (4,045) within the fiber itself to cause a SystemStackError to be raised. count = 0 loop do count += 1 puts count varlist = String.new count.times do |i| varlist += "a

Waking up by push notification

喜欢而已 提交于 2019-12-06 08:28:22
问题 Suppose: There is some object (e.g., an array a ) and a condition dependent on the object (e.g., such as a.empty? ). Some threads other than the current thread can manipulate the object ( a ), so the truthness of the evaluated value of the condition changes over the time. How can I let the current thread sleep at some point in the code and continue (wake up) by push notification when the condition is satisfied? I do not want to do polling like this: ... sleep 1 until a.empty? ... Perhaps

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

老子叫甜甜 提交于 2019-12-05 17:47:31
问题 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 Exception => ex puts "Failed at #{Time.now}" puts "Error: #{ex}" end end array_of_urls_to_process = [......] # How can I iterate over items in the array in parallel (instead of one at a time?) array_of_urls_to_process.each do |url| x = get_doc(url) do_something(x

Can Ruby Fibers be Concurrent?

♀尐吖头ヾ 提交于 2019-12-04 07:59:48
问题 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 threads you can do this: threads = [] threads << Thread.new {Do something} threads << Thread.new {Do something} threads.each {|thread| thread.join} I can't see how to do something like this with fibers. All I can find is yield and resume which seems

Fibers vs async await

大兔子大兔子 提交于 2019-12-03 09:08:35
问题 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 BackgroundWorker s to my multitasking operations. Today I was asking them why they used Fiber s and the main developer said that it's easier for him to debug. Meaning he knows which thread a particular function has come from and even could access the variables higher in the stack. I was wondering what are the advantages and

Why do we need fibers

谁都会走 提交于 2019-12-03 00:02:53
问题 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, actually) def clsr x, y = 0, 1 Proc.new do x, y = y, x + y x end end So 10.times { puts fib.resume } and prc = clsr 10.times { puts prc.call } will return just the same result. So what are the advantages of fibers. What kind of stuff I can write with Fibers I can't do

Why do we need fibers

风格不统一 提交于 2019-12-02 13:49:51
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, actually) def clsr x, y = 0, 1 Proc.new do x, y = y, x + y x end end So 10.times { puts fib.resume } and prc = clsr 10.times { puts prc.call } will return just the same result. So what are the advantages of fibers. What kind of stuff I can write with Fibers I can't do with lambdas and other cool Ruby features? Fibers are something you will probably never use directly in