threach 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +37 -1
- data/VERSION +1 -1
- metadata +5 -5
data/README.markdown
CHANGED
@@ -3,9 +3,23 @@
|
|
3
3
|
`threach` adds to the Enumerable module to provide a threaded
|
4
4
|
version of whatever enumerator you throw at it (`each` by default).
|
5
5
|
|
6
|
+
## Warning: Deadlocks under JRuby if an exception is thrown
|
7
|
+
|
8
|
+
`threach` works fine, so long as nothing goes wrong. In particular, there's no safe way (that I can find; see below) to break out of a `threach` loop without a deadlock under JRuby. This is, shall we say, an Issue.
|
9
|
+
|
10
|
+
Under vanilla ruby, `threach` will exit as expected, but who the hell wants to
|
11
|
+
use `threach` where there are no real threads???
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
`threach` is on rubygems.org, so you should just be able to do
|
16
|
+
|
17
|
+
gem install threach
|
18
|
+
# or jruby -S gem install threach
|
19
|
+
|
6
20
|
## Use
|
7
21
|
|
8
|
-
# You like #each? You'll love...err..probably like #threach
|
22
|
+
# You like #each? You'll love...err.."probably like" #threach
|
9
23
|
require 'rubygems'
|
10
24
|
require 'threach'
|
11
25
|
|
@@ -33,6 +47,28 @@ version of whatever enumerator you throw at it (`each` by default).
|
|
33
47
|
puts "#{i}: #{letter}"
|
34
48
|
end
|
35
49
|
|
50
|
+
## Major problem
|
51
|
+
|
52
|
+
I can't figure out how to exit gracefully from a threach loop.
|
53
|
+
|
54
|
+
begin
|
55
|
+
('a'..'z').threach(2, :each_with_index) do |letter, i|
|
56
|
+
break if i > 10 # will deadlock under jruby; fine under ruby
|
57
|
+
# raise StandardError if i > 10 # deadlock under jruby; find under ruby
|
58
|
+
puts letter
|
59
|
+
end
|
60
|
+
rescue
|
61
|
+
puts "Rescued; broke out of the loop"
|
62
|
+
end
|
63
|
+
|
64
|
+
The `break` under jruby prints "Exception in thread "Thread-1" org.jruby.exceptions.JumpException$BreakJump," but if there's a way to catch that in the enclosing code I sure don't know how.
|
65
|
+
|
66
|
+
Use of `catch` and `throw` seemed like an obvious choice, but they don't work across threads. Then I thought I'd use `catch` within the consumers and throw or raise an error at the producer, but that doesn't work, either.
|
67
|
+
|
68
|
+
I'm clearly up against (or well beyond) my knowledge limitations, here.
|
69
|
+
|
70
|
+
If anyone has a solution to what should be a simple problem (and works under both ruby and jruby) boy, would I be grateful.
|
71
|
+
|
36
72
|
## Why and when to use it?
|
37
73
|
|
38
74
|
Well, if you're using stock (MRI) ruby -- you probably shouldn't bother with `threach`. It'll just slow things down. But if you're using a ruby implementation that has real threads, like JRuby, this will give you relatively painless multi-threading.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: threach
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bill Dueber
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-10 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|