Skip to content

Commit 6a42240

Browse files
committed
Merge remote-tracking branch 'upstream/master' into actress
* upstream/master: (52 commits) Add test to verify that TimerSet#post returns true ...
2 parents ff37c93 + 8ef62bb commit 6a42240

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1779
-670
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: ruby
2+
23
rvm:
34
- 2.1.2
45
- 2.0.0
@@ -7,15 +8,20 @@ rvm:
78
- jruby-19mode
89
- jruby-head
910
- rbx-2
11+
1012
jdk:
1113
- oraclejdk8
14+
15+
sudo: false
16+
1217
branches:
1318
only:
1419
- master
20+
1521
matrix:
1622
allow_failures:
17-
- rvm: rbx-2
1823
- rvm: ruby-head
1924
- rvm: jruby-head
2025
- rvm: 1.9.3
26+
2127
script: "bundle exec rake compile && bundle exec rspec --color --backtrace --tag ~unfinished --seed 1 --format documentation ./spec"

.yardopts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
./lib/**/*.rb
1111
./ext/concurrent_ruby_ext/**/*.c
1212
-
13+
doc/thread_pools.md
1314
README.md
1415
LICENSE.txt

CHANGELOG.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
### Upcoming Release v0.7.1 (TBD)
1+
### Next Release v0.7.2 (TBD)
2+
3+
* New `Semaphore` class based on [java.util.concurrent.Semaphore](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Semaphore.html)
4+
* New `Promise.all?` and `Promise.any?` class methods
5+
* Renamed `:overflow_policy` on thread pools to `:fallback_policy`
6+
* Thread pools still accept the `:overflow_policy` option but display a warning
7+
* Thread pools now implement `fallback_policy` behavior when not running (rather than universally rejecting tasks)
8+
* Fixed minor `set_deref_options` constructor bug in `Promise` class
9+
* Numerous non-functional updates to clear warning when running in debug mode
10+
* Fixed more intermittently failing tests
11+
* Tests now run on new Travis build environment
12+
13+
## Current Release v0.7.1 (4 December 2014)
214

315
Please see the [roadmap](https://github.com/ruby-concurrency/concurrent-ruby/issues/142) for more information on the next planned release.
416

@@ -14,10 +26,12 @@ Please see the [roadmap](https://github.com/ruby-concurrency/concurrent-ruby/iss
1426
* Prevent `Actor` from using an `ImmediateExecutor` (causes deadlock)
1527
* Added missing synchronizations to `TimerSet`
1628
* Fixed bug with return value of `Concurrent::Actor::Utils::Pool#ask`
29+
* Fixed timing bug in `TimerTask`
30+
* Fixed bug when creating a `JavaThreadPoolExecutor` with minimum pool size of zero
1731
* Removed confusing warning when not using native extenstions
1832
* Improved documentation
1933

20-
## Current Release v0.7.0 (13 August 2014)
34+
### Release v0.7.0 (13 August 2014)
2135

2236
* Merge the [atomic](https://github.com/ruby-concurrency/atomic) gem
2337
- Pure Ruby `MutexAtomic` atomic reference class

README.md

Lines changed: 54 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -35,115 +35,68 @@
3535
</tr>
3636
</table>
3737

38-
## Features & Documentation
39-
40-
Please see the [Concurrent Ruby Wiki](https://github.com/ruby-concurrency/concurrent-ruby/wiki)
41-
or the [API documentation](http://ruby-concurrency.github.io/concurrent-ruby/frames.html)
42-
for more information or join our [mailing list](http://groups.google.com/group/concurrent-ruby).
43-
44-
There are many concurrency abstractions in this library. These abstractions can be broadly categorized
45-
into several general groups:
46-
47-
* Asynchronous concurrency abstractions including
48-
[Agent](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Agent.html),
49-
[Async](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Async.html),
50-
[Future](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Future.html),
51-
[Promise](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Promise.html),
52-
[ScheduledTask](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ScheduledTask.html),
53-
and [TimerTask](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/TimerTask.html)
54-
* Fast, light-weight [Actor model](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Actor.html) implementation.
55-
* Thread-safe variables including
56-
[I-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html),
57-
[M-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/MVar.html),
58-
[thread-local variables](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadLocalVar.html),
59-
and [software transactional memory](https://github.com/ruby-concurrency/concurrent-ruby/wiki/TVar-(STM))
60-
* Thread synchronization classes and algorithms including
61-
[condition](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Condition.html),
62-
[countdown latch](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CountDownLatch.html),
63-
[dataflow](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Dataflow),
64-
[event](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Event.html),
65-
[exchanger](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Exchanger.html),
66-
and [timeout](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timeout-class_method)
67-
* Java-inspired [executors](https://github.com/ruby-concurrency/concurrent-ruby/wiki/Thread%20Pools) (thread pools and more)
68-
* [And many more](http://ruby-concurrency.github.io/concurrent-ruby/index.html)...
69-
70-
### Semantic Versioning
71-
72-
This gem adheres to the rules of [semantic versioning](http://semver.org/).
73-
7438
### Supported Ruby versions
7539

76-
MRI 1.9.3, 2.0, 2.1, JRuby (1.9 mode), and Rubinius 2.x.
40+
MRI 1.9.3, 2.0, 2.1, JRuby (1.9 mode), and Rubinius 2.x are supported.
7741
Although native code is used for performance optimizations on some platforms, all functionality
7842
is available in pure Ruby. This gem should be fully compatible with any interpreter that is
7943
compliant with Ruby 1.9.3 or newer.
8044

81-
### Examples
82-
83-
Many more code examples can be found in the documentation for each class (linked above).
84-
85-
Future and ScheduledTask:
86-
87-
```ruby
88-
require 'concurrent'
89-
require 'thread' # for Queue
90-
require 'open-uri' # for open(uri)
91-
92-
class Ticker
93-
def get_year_end_closing(symbol, year)
94-
uri = "http://ichart.finance.yahoo.com/table.csv?s=#{symbol}&a=11&b=01&c=#{year}&d=11&e=31&f=#{year}&g=m"
95-
data = open(uri) {|f| f.collect{|line| line.strip } }
96-
data[1].split(',')[4].to_f
97-
end
98-
end
99-
100-
# Future
101-
price = Concurrent::Future.execute{ Ticker.new.get_year_end_closing('TWTR', 2013) }
102-
price.state #=> :pending
103-
sleep(1) # do other stuff
104-
price.value #=> 63.65
105-
price.state #=> :fulfilled
106-
107-
# ScheduledTask
108-
task = Concurrent::ScheduledTask.execute(2){ Ticker.new.get_year_end_closing('INTC', 2013) }
109-
task.state #=> :pending
110-
sleep(3) # do other stuff
111-
task.value #=> 25.96
112-
```
45+
## Features & Documentation
11346

114-
Actor:
47+
We have a roadmap guiding our work toward the [v1.0.0 release](https://github.com/ruby-concurrency/concurrent-ruby/wiki/v1.0-Roadmap).
11548

116-
```ruby
117-
class Counter < Concurrent::Actor::Context
118-
# Include context of an actor which gives this class access to reference
119-
# and other information about the actor
120-
121-
# use initialize as you wish
122-
def initialize(initial_value)
123-
@count = initial_value
124-
end
125-
126-
# override on_message to define actor's behaviour
127-
def on_message(message)
128-
if Integer === message
129-
@count += message
130-
end
131-
end
132-
end #
133-
134-
# Create new actor naming the instance 'first'.
135-
# Return value is a reference to the actor, the actual actor is never returned.
136-
counter = Counter.spawn(:first, 5)
137-
138-
# Tell a message and forget returning self.
139-
counter.tell(1)
140-
counter << 1
141-
# (First counter now contains 7.)
142-
143-
# Send a messages asking for a result.
144-
counter.ask(0).class
145-
counter.ask(0).value
146-
```
49+
The primary site for documentation is the automatically generated [API documentation](http://ruby-concurrency.github.io/concurrent-ruby/frames.html)
50+
51+
We also have a [mailing list](http://groups.google.com/group/concurrent-ruby).
52+
53+
This library contains a variety of concurrency abstractions at high and low levels. One of the high-level abstractions is likely to meet most common needs.
54+
55+
### High-level, general-purpose asynchronous concurrency abstractions
56+
57+
* [Actor](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Actor.html): Implements the Actor Model, where concurrent actors exchange messages.
58+
* [Agent](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Agent.html): A single atomic value that represents an identity.
59+
* [Async](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Async.html): A mixin module that provides simple asynchronous behavior to any standard class/object or object.
60+
* [Future](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Future.html): An asynchronous operation that produces a value.
61+
* [Dataflow](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Dataflow.html): Built on Futures, Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available.
62+
* [Promise](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Promise.html): Similar to Futures, with more features.
63+
* [ScheduledTask](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ScheduledTask.html): Like a Future scheduled for a specific future time.
64+
* [TimerTask](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/TimerTask.html): A Thread that periodically wakes up to perform work at regular intervals.
65+
66+
### Java-inspired ThreadPools and other executors
67+
68+
* See [ThreadPool](http://ruby-concurrency.github.io/concurrent-ruby/file.thread_pools.html) overview, which also contains a list of other Executors available.
69+
70+
### Thread-safe Observers
71+
72+
* [Concurrent::Observable](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Observable.html) mixin module
73+
* [CopyOnNotifyObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnNotifyObserverSet.html)
74+
* [CopyOnWriteObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnWriteObserverSet.html)
75+
76+
### Thread synchronization classes and algorithms
77+
78+
Lower-level abstractions mainly used as building blocks.
79+
80+
* [condition](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Condition.html)
81+
* [countdown latch](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CountDownLatch.html)
82+
* [cyclic barrier](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CyclicBarrier.html)
83+
* [event](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Event.html)
84+
* [exchanger](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Exchanger.html)
85+
* [semaphore](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Semaphore.html)
86+
* [timeout](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timeout-class_method)
87+
* [timer](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timer-class_method)
88+
89+
### Thread-safe variables
90+
91+
Lower-level abstractions mainly used as building blocks.
92+
93+
* [AtomicBoolean](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicBoolean.html)
94+
* [AtomicFixnum](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicFixnum.html)
95+
* AtomicReference (no docs currently available, check source)
96+
* [I-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html) (IVar)
97+
* [M-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/MVar.html) (MVar)
98+
* [thread-local variables](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadLocalVar.html)
99+
* [software transactional memory](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/TVar.html) (TVar)
147100

148101
## Installing and Building
149102

doc/actor/main.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,40 @@ Concurrency is hard to get right, actors are one of many ways how to simplify th
2929

3030
## Quick example
3131

32+
An example:
33+
34+
```ruby
35+
class Counter < Concurrent::Actor::Context
36+
# Include context of an actor which gives this class access to reference
37+
# and other information about the actor
38+
39+
# use initialize as you wish
40+
def initialize(initial_value)
41+
@count = initial_value
42+
end
43+
44+
# override on_message to define actor's behaviour
45+
def on_message(message)
46+
if Integer === message
47+
@count += message
48+
end
49+
end
50+
end #
51+
52+
# Create new actor naming the instance 'first'.
53+
# Return value is a reference to the actor, the actual actor is never returned.
54+
counter = Counter.spawn(:first, 5)
55+
56+
# Tell a message and forget returning self.
57+
counter.tell(1)
58+
counter << 1
59+
# (First counter now contains 7.)
60+
61+
# Send a messages asking for a result.
62+
counter.ask(0).class
63+
counter.ask(0).value
64+
```
65+
3266
{include:file:doc/actor/quick.out.rb}
3367

3468
## Spawning actors

doc/future.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,35 @@ The `Future` class also includes the behavior of the Ruby standard library [Obse
1919

2020
A fulfilled example:
2121

22-
```ruby
22+
```ruby
2323
require 'concurrent'
24+
require 'thread' # for Queue
25+
require 'open-uri' # for open(uri)
2426

25-
count = Concurrent::Future.new{ sleep(10); 10 }.execute
26-
count.state #=> :pending
27-
count.pending? #=> true
27+
class Ticker
28+
def get_year_end_closing(symbol, year)
29+
uri = "http://ichart.finance.yahoo.com/table.csv?s=#{symbol}&a=11&b=01&c=#{year}&d=11&e=31&f=#{year}&g=m"
30+
data = open(uri) {|f| f.collect{|line| line.strip } }
31+
data[1].split(',')[4].to_f
32+
end
33+
end
2834

29-
# do stuff...
35+
# Future
36+
price = Concurrent::Future.execute{ Ticker.new.get_year_end_closing('TWTR', 2013) }
37+
price.state #=> :pending
38+
price.pending? #=> true
39+
price.value(0) #=> nil (does not block)
3040

31-
count.value(0) #=> nil (does not block)
41+
sleep(1) # do other stuff
3242

33-
count.value #=> 10 (after blocking)
34-
count.state #=> :fulfilled
35-
count.fulfilled? #=> true
36-
count.value #=> 10
43+
price.value #=> 63.65 (after blocking if neccesary)
44+
price.state #=> :fulfilled
45+
price.fulfilled? #=> true
46+
price.value #=> 63.65
3747
```
3848

49+
50+
3951
A rejected example:
4052

4153
```ruby
@@ -48,6 +60,10 @@ count.rejected? #=> true
4860
count.reason #=> #<StandardError: Boom!>
4961
```
5062

63+
64+
65+
66+
5167
An example with observation:
5268

5369
```ruby

0 commit comments

Comments
 (0)