Created
March 7, 2011 01:42
-
-
Save bakkdoor/857952 to your computer and use it in GitHub Desktop.
Running fiber.fy in fancy (with JIT on)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define some additional methods | |
class Fiber { | |
def sleep: seconds { | |
@sleep_end = Time now + seconds | |
} | |
def asleep? { | |
if: @sleep_end then: { | |
Time now < @sleep_end | |
} | |
} | |
} | |
fibers = [] | |
10 times: |i| { | |
f = Fiber new: { | |
"In Fiber #{i}!" println | |
Fiber yield: i | |
"OK, done with Fiber #{i}" println | |
} | |
fibers << f | |
} | |
# simple scheduler in a thread | |
Thread new: { | |
loop: { | |
while: { fibers size > 0 } do: { | |
fibers each: |f| { | |
unless: (f asleep?) do: { | |
val = f resume | |
{ f sleep: val } if: val | |
} | |
} | |
fibers select!: 'alive? | |
} | |
Thread sleep: 1 | |
} | |
} | |
Console readln |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Equivalent ruby version of fiber.fy: | |
require "fiber" | |
class Rubinius::Fiber | |
def sleep(seconds) | |
@sleep_end = Time.now + seconds | |
end | |
def asleep? | |
if @sleep_end | |
Time.now < @sleep_end | |
end | |
end | |
end | |
fibers = [] | |
10.times do |i| | |
fibers << Rubinius::Fiber.new do | |
puts "In Fiber #{i}!" | |
Rubinius::Fiber.yield i | |
puts "OK, done with Fiber #{i}" | |
end | |
end | |
Thread.new { | |
loop do | |
while fibers.size > 0 | |
fibers.each do |f| | |
unless f.asleep? | |
val = f.resume | |
if val | |
f.sleep val | |
end | |
end | |
end | |
fibers = fibers.select{|f| f.alive?} | |
end | |
sleep 1 | |
end | |
} | |
gets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
backtype ~/projects/fancy[master*] $ gdb rbx | |
GNU gdb 6.3.50-20050815 (Apple version gdb-1510) (Wed Sep 22 02:45:02 UTC 2010) | |
Copyright 2004 Free Software Foundation, Inc. | |
GDB is free software, covered by the GNU General Public License, and you are | |
welcome to change it and/or distribute copies of it under certain conditions. | |
Type "show copying" to see the conditions. | |
There is absolutely no warranty for GDB. Type "show warranty" for details. | |
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... done | |
(gdb) set args bin/fancy fiber.fy | |
(gdb) run | |
Starting program: /Users/backtype/projects/rubinius/bin/rbx bin/fancy fiber.fy | |
Reading symbols for shared libraries ++. done | |
Reading symbols for shared libraries . done | |
Reading symbols for shared libraries . done | |
Reading symbols for shared libraries . done | |
In Fiber 0! | |
In Fiber 1! | |
In Fiber 2! | |
In Fiber 3! | |
In Fiber 4! | |
In Fiber 5! | |
In Fiber 6! | |
In Fiber 7! | |
In Fiber 8! | |
In Fiber 9! | |
OK, done with Fiber 0 | |
OK, done with Fiber 1 | |
OK, done with Fiber 2 | |
Program received signal EXC_BAD_ACCESS, Could not access memory. | |
Reason: KERN_INVALID_ADDRESS at address: 0x00000000000000b8 | |
[Switching to process 53368] | |
rubinius::JITVisit::visit_raise_return (this=0x102d46e10) at jit_visit.hpp:2912 | |
2912 creator->add_return_value(stack_pop(), b().GetInsertBlock()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
backtype ~/projects/fancy[master*] $ fancy fiber.fy | |
In Fiber 0! | |
In Fiber 1! | |
In Fiber 2! | |
In Fiber 3! | |
In Fiber 4! | |
In Fiber 5! | |
In Fiber 6! | |
In Fiber 7! | |
In Fiber 8! | |
In Fiber 9! | |
OK, done with Fiber 0 | |
OK, done with Fiber 1 | |
OK, done with Fiber 2 | |
--------------------------------------------- | |
CRASH: A fatal error has occured. | |
Backtrace: | |
0 rbx 0x00000001000201f0 _ZN8rubiniusL12segv_handlerEi + 160 | |
1 libSystem.B.dylib 0x00007fff86a4567a _sigtramp + 26 | |
2 ??? 0x0000003131326461 0x0 + 211278783585 | |
3 rbx 0x0000000100208b82 _ZN8rubinius17VisitInstructionsINS_8JITVisitEE8dispatchEi + 4962 | |
4 rbx 0x00000001001e9af4 _ZN8rubinius3jit7Builder13generate_bodyEv + 1156 | |
5 rbx 0x00000001001d2159 _ZN8rubinius7Inliner21inline_generic_methodEPNS_5ClassEPNS_6ModuleEPNS_14CompiledMethodEPNS_8VMMethodE + 1545 | |
6 rbx 0x00000001001d3abe _ZN8rubinius7Inliner8considerEv + 2206 | |
7 rbx 0x00000001001fb032 _ZN8rubinius8JITVisit16visit_send_stackEmm + 354 | |
8 rbx 0x00000001002092b5 _ZN8rubinius17VisitInstructionsINS_8JITVisitEE8dispatchEi + 6805 | |
9 rbx 0x00000001001e9af4 _ZN8rubinius3jit7Builder13generate_bodyEv + 1156 | |
10 rbx 0x00000001001d2159 _ZN8rubinius7Inliner21inline_generic_methodEPNS_5ClassEPNS_6ModuleEPNS_14CompiledMethodEPNS_8VMMethodE + 1545 | |
11 rbx 0x00000001001d3abe _ZN8rubinius7Inliner8considerEv + 2206 | |
12 rbx 0x00000001001fb032 _ZN8rubinius8JITVisit16visit_send_stackEmm + 354 | |
13 rbx 0x00000001002092b5 _ZN8rubinius17VisitInstructionsINS_8JITVisitEE8dispatchEi + 6805 | |
14 rbx 0x00000001001e9af4 _ZN8rubinius3jit7Builder13generate_bodyEv + 1156 | |
15 rbx 0x0000000100209a04 _ZN8rubinius3jit8Compiler15compile_builderERNS0_7ContextEPNS_9LLVMStateERNS_13JITMethodInfoERNS0_7BuilderE + 52 | |
16 rbx 0x000000010020a525 _ZN8rubinius3jit8Compiler13compile_blockEPNS_9LLVMStateEPNS_14CompiledMethodEPNS_8VMMethodE + 181 | |
17 rbx 0x00000001001e343a _ZN8rubinius24BackgroundCompilerThread7performEv + 1034 | |
18 rbx 0x0000000100023782 _ZN6thread6Thread10trampolineEPv + 18 | |
19 libSystem.B.dylib 0x00007fff86a1e536 _pthread_start + 331 | |
20 libSystem.B.dylib 0x00007fff86a1e3e9 thread_start + 13 | |
Wrote full error report to: /Users/backtype/.rubinius_last_error | |
Run 'rbx report' to submit this crash report! |
Note 2: Looks like calling Fiber yield with arguments causes this problem. The implementation of it is:
def Fiber yield: vals {
Fiber yield(*vals)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: The ruby version runs fine, the fancy version crashes with the JIT enabled but works fine when running with -Xint.