fiber

Why a segmentation fault occurs calling a function inside setjmp()?

倾然丶 夕夏残阳落幕 提交于 2020-01-05 03:55:08
问题 I do not understand why in the function middleFunc() , a segmentation fault is raisen when entry_point(arg) is invoked inside the if ( setjmp(middle) ) statement. #include <stdio.h> #include <setjmp.h> jmp_buf start,middle,end; void finalFunc(void *v) { printf("hello\n"); return ; } void middleFunc(void (*entry_point)(void *), void *arg) { //just debug : this does not cause segmentation fault entry_point(arg); if ( setjmp(middle) ){ //this casues the segmentation fault entry_point(arg); /

How do Enumerators work in Ruby 1.9.1?

允我心安 提交于 2019-12-20 21:00:16
问题 This question is not about how to use Enumerators in Ruby 1.9.1 but rather I am curious how they work. Here is some code: class Bunk def initialize @h = [*1..100] end def each if !block_given? enum_for(:each) else 0.upto(@h.length) { |i| yield @h[i] } end end end In the above code I can use e = Bunk.new.each , and then e.next , e.next to get each successive element, but how exactly is it suspending execution and then resuming at the right spot? I am aware that if the yield in the 0.upto is

With Boost.Fiber does c++ come one step closer to Erlang style process/threads?

混江龙づ霸主 提交于 2019-12-20 12:09:35
问题 I am reading http://olk.github.io/libs/fiber/doc/html/ It seems to me that with Boost.Fiber C++ is coming closer to Erlang's ability to have thousands of "processes", also known as "green processes[threads]" http://en.wikipedia.org/wiki/Green_threads. My question is, is Boost.Fiber ready for production, are there now c++ alternatives that have better documentation and examples? Someone mentioned lightweight threads, but I can't seem to find a reference to it. One final question is, why doesn

Is there a fiber api in .net?

冷暖自知 提交于 2019-12-17 12:24:25
问题 Out of more curiosity than anything I've been looking for a set of C#/.net classes to support fibers/co-routines (the win32 version) and haven't had any luck. Does anybody know of such a beast? 回答1: Have you seen this: Title "Implementing Coroutines for .NET by Wrapping the Unmanaged Fiber API" in the September 2003 issue of MSDN Magazine http://msdn.microsoft.com/en-us/magazine/cc164086.aspx 回答2: No. There isn't a Fiber API in the Framework. I suspect this is because there is little

Producer/Consumer using Boost.Fibers

╄→尐↘猪︶ㄣ 提交于 2019-12-11 18:55:28
问题 I'm trying to create producer/consumer using Boost.Fibers. Looks like using channels from this example is the right thing to do. The example have to be changed slightly since I want to signal completion using promise/future . So I wrote some naive code to do no work, just signal the completion. struct fiber_worker { fiber_worker() { wthread = std::thread([self{this}]() { for (int i = 0; i < 4; ++i) { boost::fibers::fiber{ [self]() { task tsk; while (boost::fibers::channel_op_status::closed !=

Fibers in C#: are they faster than iterators, and have people used them?

好久不见. 提交于 2019-12-08 22:59:00
问题 So I was chatting with a colleague about fibers and turned up this paper from 2003 that describes a implementation of coroutines in C# using the Fiber API. The implementation of Yield in this paper was for .NET 1.1, so it predates the yield return syntax that appeared in .NET 2.0. It definitely looks, at first glance, that the implementation here is potentially faster and could scale across multiple CPUs rather well. Has anyone used it? 回答1: I haven't used it, but I have an interest in the

Java Async IO Library: Quasar (use Fiber)

喜你入骨 提交于 2019-12-06 00:11:38
前言 Quasar 提供很多的功能(Go-like channels, Erlang-like actors),这篇博客主要介绍Quasar的核心Fiber和使用Fiber来处理异步IO(本博客给出的例子是发起Http 请求)。 本博客所指的线程均指Linux下的线程,Linux下不区分线程和进程,特别的地方会再做说明。 Fiber是什么? Fiber(中文翻译成纤程) 是JVM上实现的轻量级用户态线程,和go 语言的goroutine 类似。Fiber 有如下几个特点: 用户态,用户态的线程切换是非常快的,而且单个时间片可以执行更多的代码(原因:操作系统何时进行线程调度(时间片用尽,IO中断,系统调用等))。众所周知,我们在进行系统调用(比如IO请求)的时候,当前的线程就会阻塞,产生线程上下文切换(从用户态切换到内核态) Context Switch ,关于这个方面的测试请查看 How long does it take to make a context switch? ,从这里可以看出上下文切换的代价是非常高的,这也正是Fiber的优势。 轻量级,Fiber 占有的资源非常少,一个fiber大概在400 bytes of RAM,所以系统里可以同时有上百万个Fiber。 为什么使用Fiber(或者说使用Threads有什么问题)? 先看一下在JVM

Ruby的Fiber根本不是用来做并发的~

[亡魂溺海] 提交于 2019-12-05 04:30:55
本来做了一个并发抓取,以为Ruby1.9以后添加的Fiber是类似于golang那种,可以实现并发运行,可是发现效率没有提高,为了确认Fiber是不是在并发执行,于是我做了一个这样的测试代码。 首先搞一个php文件: <?php $i = intval(isset($_GET['i']) ? $_GET['i'] : (!empty($argv[1]) ? $argv[1] : 0)); if($i>0){ sleep(5-$i); } echo $i, "\n"; 然后用命令行测试,确认这个php文件是不会block的(因为没有session锁,应该不会block) time for i in {1..5}; do (curl localhost/test.php?i=$i) & if [ "$i" -eq "5" ]; then wait; fi ; done time for i in {1..5}; do (php test.php $i) & if [ "$i" -eq "5" ]; then wait; fi ; done 这里两种方式运行时间都是4秒左右,证明,是可以并行运行。 real 0m4.019s 然后用fiber执行: real 0m10.086s 10秒左右,证明这完全是一个一个在跑的。 #!/usr/bin/env ruby require 'open

Lightweight, portable C++ fibers, MIT license

牧云@^-^@ 提交于 2019-12-03 07:30:46
问题 I would like to get ahold of a lightweight, portable fiber lib with MIT license (or looser). Boost.Coroutine does not qualify (not lightweight), neither do Portable Coroutine Library nor Kent C++CSP (both GPL). Edit: could you help me find one? :) 回答1: Libtask: MIT License Libconcurrency: LGPL (a little tighter than MIT, but it's a functional library!) Both are written for C. 回答2: I actually blogged about this in the past. Have a look! I hope it answers your questions. In it, I cover a number

How do Enumerators work in Ruby 1.9.1?

人盡茶涼 提交于 2019-12-03 07:04:18
This question is not about how to use Enumerators in Ruby 1.9.1 but rather I am curious how they work. Here is some code: class Bunk def initialize @h = [*1..100] end def each if !block_given? enum_for(:each) else 0.upto(@h.length) { |i| yield @h[i] } end end end In the above code I can use e = Bunk.new.each , and then e.next , e.next to get each successive element, but how exactly is it suspending execution and then resuming at the right spot? I am aware that if the yield in the 0.upto is replaced with Fiber.yield then it's easy to understand, but that is not the case here. It is a plain old