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
| class Fiber | |
| def initialize &blk | |
| unless @yield = callcc{|c| c } | |
| @ret = blk.call(@ret) | |
| @resume.call | |
| end | |
| end | |
| def resume *args | |
| if @resume = callcc{|c| c } |
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
| $ cat fbbench.rb | |
| FIBER_NUM = 503 | |
| number = ARGV.first.to_i | |
| threads = [] | |
| for i in 1..FIBER_NUM | |
| threads << Fiber.new do |num| | |
| while true | |
| Fiber.yield | |
| if number > 0 |
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
| diff --git a/eval.c b/eval.c | |
| index 11264f7..01d127b 100644 | |
| --- a/eval.c | |
| +++ b/eval.c | |
| @@ -1026,6 +1026,7 @@ static struct tag *prot_tag; | |
| #define PROT_LOOP INT2FIX(1) /* 3 */ | |
| #define PROT_LAMBDA INT2FIX(2) /* 5 */ | |
| #define PROT_YIELD INT2FIX(3) /* 7 */ | |
| +#define PROT_FIBER INT2FIX(4) /* 9 */ | |
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
| git clone git://github.com/tmm1/ruby187 | |
| cd ruby187 | |
| git checkout -b fibers origin/fibers | |
| CFLAGS="-O2 -ggdb" ./configure --disable-pthread --prefix=/tmp/ruby-with-fibers | |
| make && sudo make install | |
| /tmp/ruby-with-fibers/bin/ruby test/test_fiber.rb | |
| cd /tmp | |
| wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz | |
| tar zxvf rubygems-1.3.1.tgz |
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
| require 'rubygems' | |
| require 'sinatra' | |
| # eventmachine/thin | |
| require 'eventmachine' | |
| require 'thin' | |
| # mysql | |
| require 'mysqlplus' | |
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
| ## | |
| # sync api: return values and exceptions | |
| begin | |
| images = [] | |
| results = RestClient.get('http://google.com/search?q=ruby') | |
| Hpricot(results).find('a').each{ |link| | |
| page = RestClient.get(link) | |
| begin |
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
| diff --git a/lib/sequel_core/adapters/mysql.rb b/lib/sequel_core/adapters/mysql.rb | |
| index 89684cf..e7fdd77 100644 | |
| --- a/lib/sequel_core/adapters/mysql.rb | |
| +++ b/lib/sequel_core/adapters/mysql.rb | |
| @@ -58,6 +58,10 @@ module Sequel | |
| opts = server_opts(server) | |
| conn = Mysql.init | |
| conn.options(Mysql::OPT_LOCAL_INFILE, "client") | |
| + if encoding = opts[:encoding] || opts[:charset] | |
| + # set charset _before_ the connect. using an option instead of "SET (NAMES|CHARACTER_SET_*)" works across reconnects |
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
| class FiberedMutex | |
| # | |
| # Creates a new FiberedMutex | |
| # | |
| def initialize | |
| @waiting = [] | |
| @locked = false | |
| end | |
| # |
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
| > - In ruby 1.8.x, what is the functional difference between rb_thread_schedule and rb_thread_select? | |
| rb_thread_schedule() is the guts of the thread scheduler, it traverses | |
| over the linked list of threads (several times) to find the next one | |
| to switch into. The function is long (250 lines) and messy, and covers | |
| all the combinations of thread status (RUNNABLE, TO_KILL, STOPPED, | |
| KILLED) and wait state (FD, SELECT, TIME, JOIN, PID). | |
| If there are no threads doing i/o or waiting on a timeout, | |
| rb_thread_schedule() picks another thread from the list (considering |
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
| class FiberedQueue | |
| def initialize | |
| @queue = [] | |
| @busy = false | |
| end | |
| def busy? | |
| !!@busy | |
| end | |