|
35 | 35 | </tr>
|
36 | 36 | </table>
|
37 | 37 |
|
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 |
| - |
74 | 38 | ### Supported Ruby versions
|
75 | 39 |
|
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. |
77 | 41 | Although native code is used for performance optimizations on some platforms, all functionality
|
78 | 42 | is available in pure Ruby. This gem should be fully compatible with any interpreter that is
|
79 | 43 | compliant with Ruby 1.9.3 or newer.
|
80 | 44 |
|
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 |
| 46 | + |
| 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). |
| 48 | + |
| 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](./doc/actor/main.md): Implements the Actor Model, where concurrent actors exchange messages. |
| 58 | +* [Agent](./doc/agent.md): A single atomic value that represents an identity. |
| 59 | +* [Async](./doc/async.md): A mixin module that provides simple asynchronous behavior to any standard class/object or object. |
| 60 | +* [Future](./doc/future.md): An asynchronous operation that produces a value. |
| 61 | + * [Dataflow](./doc/dataflow.md): Built on Futures, Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available. |
| 62 | +* [Promise](./doc/promise.md): Similar to Futures, with more features. |
| 63 | +* [ScheduledTask](./doc/scheduled_task.md): 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 | + |
| 67 | +### Java-inspired ThreadPools and other executors |
| 68 | + |
| 69 | +* See [ThreadPool](./doc/thread_pools.md) overview, which also contains a list of other Executors available. |
| 70 | + |
| 71 | +### Thread-safe Observers |
| 72 | + |
| 73 | +* [Concurrent::Observable](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Observable.html) mixin module |
| 74 | +* [CopyOnNotifyObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnNotifyObserverSet.html) |
| 75 | +* [CopyOnWriteObserverSet](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/CopyOnWriteObserverSet.html) |
| 76 | + |
| 77 | +### Thread synchronization classes and algorithms |
| 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 | +* [timeout](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timeout-class_method) |
| 86 | +* [timer](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#timer-class_method) |
| 87 | + |
| 88 | +### Thread-safe variables |
| 89 | +Lower-level abstractions mainly used as building blocks. |
| 90 | + |
| 91 | +* [AtomicBoolean](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicBoolean.html) |
| 92 | +* [AtomicFixnum](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/AtomicFixnum.html) |
| 93 | +* AtomicReference (no docs currently available, check source) |
| 94 | +* [I-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/IVar.html) (IVar) |
| 95 | +* [M-Structures](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/MVar.html) (MVar) |
| 96 | +* [thread-local variables](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadLocalVar.html) |
| 97 | +* [software transactional memory](./doc/tvar.md) (TVar) |
113 | 98 |
|
114 |
| -Actor: |
115 | 99 |
|
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 |
| -``` |
147 | 100 |
|
148 | 101 | ## Installing and Building
|
149 | 102 |
|
|
0 commit comments