Skip to content

Instantly share code, notes, and snippets.

@takaokouji
Created October 25, 2009 02:55
Show Gist options
  • Save takaokouji/217860 to your computer and use it in GitHub Desktop.
Save takaokouji/217860 to your computer and use it in GitHub Desktop.
q_default = Dispatch::Queue.concurrent
q_sum = Dispatch::Queue.new("com.example.sum")
sum = 0
q_default.apply(10) do |i|
puts("i: #{i}")
sleep(1)
x = i + 1
q_sum.dispatch(false, &lambda {
puts("x: #{x}")
sum += x
})
end
q_sum.dispatch(true) do
puts("sum: #{sum}")
end
run on gdb
(gdb) r 002_n.rb
Starting program: /usr/local/bin/macruby 002_n.rb
i: 0i: 1
i: 2
x: 2
x: 1
i: 3
i: 4x: 3
i: 5
x: 4
i: 6
x: 5
i: 7
x: 6
i: 8
x: 7
x: 8
i: 9
x: 9
x: 10
sum: 55
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000001000000017
rb_vm_keep_vars (uses=<value temporarily unavailable, due to optimizations>, lvars_size=3) at vm.cpp:2622
2622 locals_to_replace = binding->locals;
backtrace:
#0 rb_vm_keep_vars (uses=<value temporarily unavailable, due to optimizations>, lvars_size=3) at vm.cpp:2622
#1 0x0000000101110389 in ?? ()
#2 0x000000010003f939 in ruby_run_node (n=0x4) at eval.c:198
#3 0x0000000100000dd8 in main (argc=2, argv=0x100f1c330, envp=<value temporarily unavailable, due to optimizations>) at main.cpp:42
#0 rb_vm_keep_vars (uses=<value temporarily unavailable, due to optimizations>, lvars_size=3) at vm.cpp:2622
2622 locals_to_replace = binding->locals;
Current language: auto; currently c++
(gdb) l
2617
2618 locals_to_replace = block->locals;
2619 }
2620 else { // VM_LVAR_USE_TYPE_BINDING
2621 rb_vm_binding_t *binding = (rb_vm_binding_t *)use;
2622 locals_to_replace = binding->locals;
2623 }
2624
2625 for (rb_vm_local_t *l = locals_to_replace; l != NULL; l = l->next) {
2626 for (int lvar_index = 0; lvar_index < lvars_size; ++lvar_index) {
#1 0x0000000101110389 in ?? ()
(gdb) l
2627 if (l->value == locals[lvar_index].stack_address) {
2628 GC_WB(&l->value, locals[lvar_index].new_address);
2629 break;
2630 }
2631 }
2632 }
2633
2634 // indicate to the GC that we do not have a reference here anymore
2635 rb_gc_assign_weak_ref(NULL, &current->uses[use_index]);
2636 }
#2 0x000000010003f939 in ruby_run_node (n=0x4) at eval.c:198
198 rb_vm_run(RSTRING_PTR(rb_progname), (NODE *)n, NULL, false);
Current language: auto; currently c
(gdb) l
193 return EXIT_FAILURE;
194 }
195 else if (FIXNUM_P(n)) {
196 return FIX2INT(n);
197 }
198 rb_vm_run(RSTRING_PTR(rb_progname), (NODE *)n, NULL, false);
199 return ruby_cleanup(0);
200 }
201
202 /*
#3 0x0000000100000dd8 in main (argc=2, argv=0x100f1c330, envp=<value temporarily unavailable, due to optimizations>) at main.cpp:42
42 rb_exit(ruby_run_node(node));
Current language: auto; currently c++
(gdb) l
37 if (ruby_aot_compile) {
38 rb_vm_aot_compile((NODE *)node);
39 rb_exit(0);
40 }
41 else {
42 rb_exit(ruby_run_node(node));
43 }
44 }
45 catch (...) {
46 rb_vm_print_current_exception();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment