Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix name collision for jruby - thx charles nutter

  • Loading branch information...
commit d09d911766b24009a3c15628782a2430071d472e 1 parent eb907db
@ahoward authored
Showing with 39 additions and 9 deletions.
  1. +12 −4 README
  2. +8 −0 README.erb
  3. +18 −4 lib/threadify.rb
  4. +1 −1  threadify.gemspec
View
16 README
@@ -64,9 +64,9 @@ SAMPLES
~ > ruby sample/a.rb
---
- without threadify: 12.6283850669861
+ without threadify: 8.49043202400208
---
- with threadify: 1.93842315673828
+ with threadify: 2.45102596282959
<========< sample/b.rb >========>
@@ -118,9 +118,9 @@ SAMPLES
~ > ruby sample/b.rb
---
- without threadify: 22.8657438755035
+ without threadify: 19.2692859172821
---
- with threadify: 0.967911005020142
+ with threadify: 0.851074934005737
---
:needle: 42
:a: 42
@@ -130,6 +130,14 @@ SAMPLES
HISTORY
+ 1.4.2
+ - fix name collision running under jruby's native threads. thanks charles nutter!
+
+ 1.3.0
+ - added Threadify(*args, &block) method to execute arbitrary code in parallel
+
+ Threadify(8){ puts Thread.current.object_id }.size #=> 8
+
1.1.0
- added ability to specify arbitrary iterator (not only each)
[0,1,2,3].threadify(:each_slice, 2){|ary| ary}
View
8 README.erb
@@ -22,6 +22,14 @@ SAMPLES
HISTORY
+ 1.4.2
+ - fix name collision running under jruby's native threads. thanks charles nutter!
+
+ 1.3.0
+ - added Threadify(*args, &block) method to execute arbitrary code in parallel
+
+ Threadify(8){ puts Thread.current.object_id }.size #=> 8
+
1.1.0
- added ability to specify arbitrary iterator (not only each)
[0,1,2,3].threadify(:each_slice, 2){|ary| ary}
View
22 lib/threadify.rb
@@ -1,5 +1,5 @@
module Threadify
- Threadify::VERSION = '1.2.0' unless defined?(Threadify::VERSION)
+ Threadify::VERSION = '1.4.2' unless defined?(Threadify::VERSION)
def Threadify.version() Threadify::VERSION end
require 'thread'
@@ -18,6 +18,20 @@ class << self
class Error < ::StandardError; end
end
+def Threadify(*args, &block)
+ # setup
+ #
+ opts = args.last.is_a?(Hash) ? args.pop : {}
+ opts.keys.each{|key| opts[key.to_s.to_sym] = opts.delete(key)}
+ opts[:threads] ||= (Numeric === args.first ? args.shift : Threadify.threads)
+ opts[:strategy] ||= (args.empty? ? Threadify.strategy : args)
+
+ threads = Integer(opts[:threads])
+
+ array_of_blocks = Array.new(threads){ block }
+ array_of_blocks.threadify(opts){|b| b.call()}
+end
+
module Enumerable
def threadify(*args, &block)
# setup
@@ -76,8 +90,8 @@ def threadify(*args, &block)
break if caught
job = jobsi.shift
break if job == done
- args = job.first
- jobsi << (job << block.call(*args))
+ argv = job.first
+ jobsi << (job << block.call(*argv))
}
nothing
end
@@ -85,7 +99,7 @@ def threadify(*args, &block)
unless nothing == thrown
thrownq.push [i, thrown]
- args, i = job
+ argv, i = job
end
end
end
View
2  threadify.gemspec
@@ -3,7 +3,7 @@
Gem::Specification::new do |spec|
spec.name = "threadify"
- spec.version = "1.1.0"
+ spec.version = "1.4.2"
spec.platform = Gem::Platform::RUBY
spec.summary = "threadify"
Please sign in to comment.
Something went wrong with that request. Please try again.