parallizer 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -161,5 +161,5 @@ http_service.get('www.google.com', '/?q=foo') # Will be called up to 4 times
161
161
 
162
162
  # Copyright
163
163
 
164
- Copyright (c) 2012 Michael Pearce, Bookrenter.com. See LICENSE.txt for further details.
164
+ Copyright (c) 2012 Michael Pearce, Rafter.com. See LICENSE.txt for further details.
165
165
 
data/lib/parallizer.rb CHANGED
@@ -4,6 +4,8 @@ require 'parallizer/proxy'
4
4
  require 'parallizer/method_call_notifier'
5
5
 
6
6
  class Parallizer
7
+ WORK_QUEUE_SIZE = 10
8
+
7
9
  attr_reader :calls, :call_infos, :client, :proxy, :options
8
10
 
9
11
  def initialize(client, options = {})
@@ -47,7 +49,20 @@ class Parallizer
47
49
  end
48
50
 
49
51
  def self.work_queue
50
- @parallizer_work_queue ||= WorkQueue.new(10)
52
+ @parallizer_work_queue ||= create_work_queue
53
+ end
54
+
55
+ def self.create_work_queue
56
+ work_queue = WorkQueue.new(WORK_QUEUE_SIZE)
57
+
58
+ # Force threads to be available - the work_queue gem seems to not always create the threads
59
+ WORK_QUEUE_SIZE.times do |i|
60
+ work_queue.enqueue_b do
61
+ 1000.times { |i| i ** 1000 }
62
+ end
63
+ end
64
+
65
+ work_queue
51
66
  end
52
67
 
53
68
  private
@@ -67,7 +82,7 @@ class Parallizer
67
82
  end
68
83
  ensure
69
84
  call_info[:complete?] = true
70
- call_info[:condition_variable].signal
85
+ call_info[:condition_variable].broadcast
71
86
  end
72
87
  end
73
88
  end
@@ -1,3 +1,3 @@
1
1
  class Parallizer
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -21,6 +21,12 @@ describe Parallizer do
21
21
  end
22
22
  end
23
23
 
24
+ describe "#work_queue" do
25
+ it "should have WORK_QUEUE_SIZE threads" do
26
+ Parallizer.work_queue.cur_threads.should == Parallizer::WORK_QUEUE_SIZE
27
+ end
28
+ end
29
+
24
30
  describe "#add" do
25
31
  before do
26
32
  @client = TestObject.new
@@ -148,4 +154,26 @@ describe Parallizer do
148
154
  end
149
155
  end
150
156
  end
157
+
158
+ context "with multiple threads making calls to proxy before worker executed" do
159
+ it "should not deadlock" do # note, this was deadlocking when using CV#signal instead of CV#broadcast
160
+ # force our worker thread to run after two calls from other threads
161
+ Parallizer::WORK_QUEUE_SIZE.times do
162
+ Parallizer.work_queue.enqueue_b do
163
+ sleep(2)
164
+ end
165
+ end
166
+
167
+ # setup the proxy
168
+ parallizer = Parallizer.new(TestObject.new)
169
+ parallizer.add.another_method
170
+ proxy = parallizer.create_proxy
171
+
172
+ Thread.new do
173
+ proxy.another_method # call in another thread must happen before call in main thread for it to deadlock
174
+ end
175
+ sleep(1)
176
+ proxy.another_method
177
+ end
178
+ end
151
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: work_queue