o-concurrent-ruby 1.1.11

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.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +542 -0
  3. data/Gemfile +37 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +404 -0
  6. data/Rakefile +307 -0
  7. data/ext/concurrent-ruby/ConcurrentRubyService.java +17 -0
  8. data/ext/concurrent-ruby/com/concurrent_ruby/ext/AtomicReferenceLibrary.java +175 -0
  9. data/ext/concurrent-ruby/com/concurrent_ruby/ext/JRubyMapBackendLibrary.java +248 -0
  10. data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaAtomicBooleanLibrary.java +93 -0
  11. data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaAtomicFixnumLibrary.java +113 -0
  12. data/ext/concurrent-ruby/com/concurrent_ruby/ext/JavaSemaphoreLibrary.java +189 -0
  13. data/ext/concurrent-ruby/com/concurrent_ruby/ext/SynchronizationLibrary.java +307 -0
  14. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/ConcurrentHashMap.java +31 -0
  15. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/ConcurrentHashMapV8.java +3863 -0
  16. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/LongAdder.java +203 -0
  17. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/Striped64.java +342 -0
  18. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/ConcurrentHashMapV8.java +3800 -0
  19. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/LongAdder.java +204 -0
  20. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166e/nounsafe/Striped64.java +291 -0
  21. data/ext/concurrent-ruby/com/concurrent_ruby/ext/jsr166y/ThreadLocalRandom.java +199 -0
  22. data/lib/concurrent-ruby/concurrent/agent.rb +587 -0
  23. data/lib/concurrent-ruby/concurrent/array.rb +66 -0
  24. data/lib/concurrent-ruby/concurrent/async.rb +449 -0
  25. data/lib/concurrent-ruby/concurrent/atom.rb +222 -0
  26. data/lib/concurrent-ruby/concurrent/atomic/abstract_thread_local_var.rb +66 -0
  27. data/lib/concurrent-ruby/concurrent/atomic/atomic_boolean.rb +126 -0
  28. data/lib/concurrent-ruby/concurrent/atomic/atomic_fixnum.rb +143 -0
  29. data/lib/concurrent-ruby/concurrent/atomic/atomic_markable_reference.rb +164 -0
  30. data/lib/concurrent-ruby/concurrent/atomic/atomic_reference.rb +205 -0
  31. data/lib/concurrent-ruby/concurrent/atomic/count_down_latch.rb +100 -0
  32. data/lib/concurrent-ruby/concurrent/atomic/cyclic_barrier.rb +128 -0
  33. data/lib/concurrent-ruby/concurrent/atomic/event.rb +109 -0
  34. data/lib/concurrent-ruby/concurrent/atomic/java_count_down_latch.rb +42 -0
  35. data/lib/concurrent-ruby/concurrent/atomic/java_thread_local_var.rb +37 -0
  36. data/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_boolean.rb +62 -0
  37. data/lib/concurrent-ruby/concurrent/atomic/mutex_atomic_fixnum.rb +75 -0
  38. data/lib/concurrent-ruby/concurrent/atomic/mutex_count_down_latch.rb +44 -0
  39. data/lib/concurrent-ruby/concurrent/atomic/mutex_semaphore.rb +131 -0
  40. data/lib/concurrent-ruby/concurrent/atomic/read_write_lock.rb +254 -0
  41. data/lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb +377 -0
  42. data/lib/concurrent-ruby/concurrent/atomic/ruby_thread_local_var.rb +181 -0
  43. data/lib/concurrent-ruby/concurrent/atomic/semaphore.rb +166 -0
  44. data/lib/concurrent-ruby/concurrent/atomic/thread_local_var.rb +104 -0
  45. data/lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb +56 -0
  46. data/lib/concurrent-ruby/concurrent/atomic_reference/numeric_cas_wrapper.rb +28 -0
  47. data/lib/concurrent-ruby/concurrent/atomics.rb +10 -0
  48. data/lib/concurrent-ruby/concurrent/collection/copy_on_notify_observer_set.rb +107 -0
  49. data/lib/concurrent-ruby/concurrent/collection/copy_on_write_observer_set.rb +111 -0
  50. data/lib/concurrent-ruby/concurrent/collection/java_non_concurrent_priority_queue.rb +84 -0
  51. data/lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb +158 -0
  52. data/lib/concurrent-ruby/concurrent/collection/map/atomic_reference_map_backend.rb +927 -0
  53. data/lib/concurrent-ruby/concurrent/collection/map/mri_map_backend.rb +66 -0
  54. data/lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb +140 -0
  55. data/lib/concurrent-ruby/concurrent/collection/map/synchronized_map_backend.rb +82 -0
  56. data/lib/concurrent-ruby/concurrent/collection/map/truffleruby_map_backend.rb +14 -0
  57. data/lib/concurrent-ruby/concurrent/collection/non_concurrent_priority_queue.rb +143 -0
  58. data/lib/concurrent-ruby/concurrent/collection/ruby_non_concurrent_priority_queue.rb +160 -0
  59. data/lib/concurrent-ruby/concurrent/concern/deprecation.rb +34 -0
  60. data/lib/concurrent-ruby/concurrent/concern/dereferenceable.rb +73 -0
  61. data/lib/concurrent-ruby/concurrent/concern/logging.rb +32 -0
  62. data/lib/concurrent-ruby/concurrent/concern/obligation.rb +220 -0
  63. data/lib/concurrent-ruby/concurrent/concern/observable.rb +110 -0
  64. data/lib/concurrent-ruby/concurrent/configuration.rb +188 -0
  65. data/lib/concurrent-ruby/concurrent/constants.rb +8 -0
  66. data/lib/concurrent-ruby/concurrent/dataflow.rb +81 -0
  67. data/lib/concurrent-ruby/concurrent/delay.rb +199 -0
  68. data/lib/concurrent-ruby/concurrent/errors.rb +69 -0
  69. data/lib/concurrent-ruby/concurrent/exchanger.rb +352 -0
  70. data/lib/concurrent-ruby/concurrent/executor/abstract_executor_service.rb +131 -0
  71. data/lib/concurrent-ruby/concurrent/executor/cached_thread_pool.rb +62 -0
  72. data/lib/concurrent-ruby/concurrent/executor/executor_service.rb +185 -0
  73. data/lib/concurrent-ruby/concurrent/executor/fixed_thread_pool.rb +220 -0
  74. data/lib/concurrent-ruby/concurrent/executor/immediate_executor.rb +66 -0
  75. data/lib/concurrent-ruby/concurrent/executor/indirect_immediate_executor.rb +44 -0
  76. data/lib/concurrent-ruby/concurrent/executor/java_executor_service.rb +103 -0
  77. data/lib/concurrent-ruby/concurrent/executor/java_single_thread_executor.rb +30 -0
  78. data/lib/concurrent-ruby/concurrent/executor/java_thread_pool_executor.rb +140 -0
  79. data/lib/concurrent-ruby/concurrent/executor/ruby_executor_service.rb +82 -0
  80. data/lib/concurrent-ruby/concurrent/executor/ruby_single_thread_executor.rb +21 -0
  81. data/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb +368 -0
  82. data/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb +35 -0
  83. data/lib/concurrent-ruby/concurrent/executor/serial_executor_service.rb +34 -0
  84. data/lib/concurrent-ruby/concurrent/executor/serialized_execution.rb +107 -0
  85. data/lib/concurrent-ruby/concurrent/executor/serialized_execution_delegator.rb +28 -0
  86. data/lib/concurrent-ruby/concurrent/executor/simple_executor_service.rb +100 -0
  87. data/lib/concurrent-ruby/concurrent/executor/single_thread_executor.rb +57 -0
  88. data/lib/concurrent-ruby/concurrent/executor/thread_pool_executor.rb +88 -0
  89. data/lib/concurrent-ruby/concurrent/executor/timer_set.rb +172 -0
  90. data/lib/concurrent-ruby/concurrent/executors.rb +20 -0
  91. data/lib/concurrent-ruby/concurrent/future.rb +141 -0
  92. data/lib/concurrent-ruby/concurrent/hash.rb +59 -0
  93. data/lib/concurrent-ruby/concurrent/immutable_struct.rb +101 -0
  94. data/lib/concurrent-ruby/concurrent/ivar.rb +207 -0
  95. data/lib/concurrent-ruby/concurrent/map.rb +346 -0
  96. data/lib/concurrent-ruby/concurrent/maybe.rb +229 -0
  97. data/lib/concurrent-ruby/concurrent/mutable_struct.rb +239 -0
  98. data/lib/concurrent-ruby/concurrent/mvar.rb +242 -0
  99. data/lib/concurrent-ruby/concurrent/options.rb +42 -0
  100. data/lib/concurrent-ruby/concurrent/promise.rb +580 -0
  101. data/lib/concurrent-ruby/concurrent/promises.rb +2167 -0
  102. data/lib/concurrent-ruby/concurrent/re_include.rb +58 -0
  103. data/lib/concurrent-ruby/concurrent/scheduled_task.rb +331 -0
  104. data/lib/concurrent-ruby/concurrent/set.rb +74 -0
  105. data/lib/concurrent-ruby/concurrent/settable_struct.rb +139 -0
  106. data/lib/concurrent-ruby/concurrent/synchronization/abstract_lockable_object.rb +98 -0
  107. data/lib/concurrent-ruby/concurrent/synchronization/abstract_object.rb +24 -0
  108. data/lib/concurrent-ruby/concurrent/synchronization/abstract_struct.rb +171 -0
  109. data/lib/concurrent-ruby/concurrent/synchronization/condition.rb +60 -0
  110. data/lib/concurrent-ruby/concurrent/synchronization/jruby_lockable_object.rb +13 -0
  111. data/lib/concurrent-ruby/concurrent/synchronization/jruby_object.rb +45 -0
  112. data/lib/concurrent-ruby/concurrent/synchronization/lock.rb +36 -0
  113. data/lib/concurrent-ruby/concurrent/synchronization/lockable_object.rb +72 -0
  114. data/lib/concurrent-ruby/concurrent/synchronization/mri_object.rb +44 -0
  115. data/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb +88 -0
  116. data/lib/concurrent-ruby/concurrent/synchronization/object.rb +183 -0
  117. data/lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb +71 -0
  118. data/lib/concurrent-ruby/concurrent/synchronization/rbx_object.rb +49 -0
  119. data/lib/concurrent-ruby/concurrent/synchronization/truffleruby_object.rb +47 -0
  120. data/lib/concurrent-ruby/concurrent/synchronization/volatile.rb +36 -0
  121. data/lib/concurrent-ruby/concurrent/synchronization.rb +30 -0
  122. data/lib/concurrent-ruby/concurrent/thread_safe/synchronized_delegator.rb +50 -0
  123. data/lib/concurrent-ruby/concurrent/thread_safe/util/adder.rb +74 -0
  124. data/lib/concurrent-ruby/concurrent/thread_safe/util/cheap_lockable.rb +118 -0
  125. data/lib/concurrent-ruby/concurrent/thread_safe/util/data_structures.rb +88 -0
  126. data/lib/concurrent-ruby/concurrent/thread_safe/util/power_of_two_tuple.rb +38 -0
  127. data/lib/concurrent-ruby/concurrent/thread_safe/util/striped64.rb +246 -0
  128. data/lib/concurrent-ruby/concurrent/thread_safe/util/volatile.rb +75 -0
  129. data/lib/concurrent-ruby/concurrent/thread_safe/util/xor_shift_random.rb +50 -0
  130. data/lib/concurrent-ruby/concurrent/thread_safe/util.rb +16 -0
  131. data/lib/concurrent-ruby/concurrent/timer_task.rb +311 -0
  132. data/lib/concurrent-ruby/concurrent/tuple.rb +86 -0
  133. data/lib/concurrent-ruby/concurrent/tvar.rb +221 -0
  134. data/lib/concurrent-ruby/concurrent/utility/engine.rb +56 -0
  135. data/lib/concurrent-ruby/concurrent/utility/monotonic_time.rb +90 -0
  136. data/lib/concurrent-ruby/concurrent/utility/native_extension_loader.rb +79 -0
  137. data/lib/concurrent-ruby/concurrent/utility/native_integer.rb +53 -0
  138. data/lib/concurrent-ruby/concurrent/utility/processor_counter.rb +130 -0
  139. data/lib/concurrent-ruby/concurrent/version.rb +3 -0
  140. data/lib/concurrent-ruby/concurrent-ruby.rb +5 -0
  141. data/lib/concurrent-ruby/concurrent.rb +134 -0
  142. metadata +192 -0
data/README.md ADDED
@@ -0,0 +1,404 @@
1
+ # Concurrent Ruby
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/concurrent-ruby.svg)](http://badge.fury.io/rb/concurrent-ruby)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
5
+ [![Gitter chat](https://img.shields.io/badge/IRC%20(gitter)-devs%20%26%20users-brightgreen.svg)](https://gitter.im/ruby-concurrency/concurrent-ruby)
6
+
7
+ Modern concurrency tools for Ruby. Inspired by
8
+ [Erlang](http://www.erlang.org/doc/reference_manual/processes.html),
9
+ [Clojure](http://clojure.org/concurrent_programming),
10
+ [Scala](http://akka.io/),
11
+ [Haskell](http://www.haskell.org/haskellwiki/Applications_and_libraries/Concurrency_and_parallelism#Concurrent_Haskell),
12
+ [F#](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx),
13
+ [C#](http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx),
14
+ [Java](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html),
15
+ and classic concurrency patterns.
16
+
17
+ <img src="https://raw.githubusercontent.com/ruby-concurrency/concurrent-ruby/master/docs-source/logo/concurrent-ruby-logo-300x300.png" align="right" style="margin-left: 20px;" />
18
+
19
+ The design goals of this gem are:
20
+
21
+ * Be an 'unopinionated' toolbox that provides useful utilities without debating which is better
22
+ or why
23
+ * Remain free of external gem dependencies
24
+ * Stay true to the spirit of the languages providing inspiration
25
+ * But implement in a way that makes sense for Ruby
26
+ * Keep the semantics as idiomatic Ruby as possible
27
+ * Support features that make sense in Ruby
28
+ * Exclude features that don't make sense in Ruby
29
+ * Be small, lean, and loosely coupled
30
+ * Thread-safety
31
+ * Backward compatibility
32
+
33
+ ## Contributing
34
+
35
+ **This gem depends on
36
+ [contributions](https://github.com/ruby-concurrency/concurrent-ruby/graphs/contributors) and we
37
+ appreciate your help. Would you like to contribute? Great! Have a look at
38
+ [issues with `looking-for-contributor` label](https://github.com/ruby-concurrency/concurrent-ruby/issues?q=is%3Aissue+is%3Aopen+label%3Alooking-for-contributor).** And if you pick something up let us know on the issue.
39
+
40
+ You can also get started by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to concurrent-ruby on CodeTriage](https://www.codetriage.com/ruby-concurrency/concurrent-ruby). [![Open Source Helpers](https://www.codetriage.com/ruby-concurrency/concurrent-ruby/badges/users.svg)](https://www.codetriage.com/ruby-concurrency/concurrent-ruby)
41
+
42
+ ## Thread Safety
43
+
44
+ *Concurrent Ruby makes one of the strongest thread safety guarantees of any Ruby concurrency
45
+ library, providing consistent behavior and guarantees on all four of the main Ruby interpreters
46
+ (MRI/CRuby, JRuby, Rubinius, TruffleRuby).*
47
+
48
+ Every abstraction in this library is thread safe. Specific thread safety guarantees are documented
49
+ with each abstraction.
50
+
51
+ It is critical to remember, however, that Ruby is a language of mutable references. *No*
52
+ concurrency library for Ruby can ever prevent the user from making thread safety mistakes (such as
53
+ sharing a mutable object between threads and modifying it on both threads) or from creating
54
+ deadlocks through incorrect use of locks. All the library can do is provide safe abstractions which
55
+ encourage safe practices. Concurrent Ruby provides more safe concurrency abstractions than any
56
+ other Ruby library, many of which support the mantra of
57
+ ["Do not communicate by sharing memory; instead, share memory by communicating"](https://blog.golang.org/share-memory-by-communicating).
58
+ Concurrent Ruby is also the only Ruby library which provides a full suite of thread safe and
59
+ immutable variable types and data structures.
60
+
61
+ We've also initiated discussion to document [memory model](docs-source/synchronization.md) of Ruby which
62
+ would provide consistent behaviour and guarantees on all four of the main Ruby interpreters
63
+ (MRI/CRuby, JRuby, Rubinius, TruffleRuby).
64
+
65
+ ## Features & Documentation
66
+
67
+ **The primary site for documentation is the automatically generated
68
+ [API documentation](http://ruby-concurrency.github.io/concurrent-ruby/index.html) which is up to
69
+ date with latest release.** This readme matches the master so may contain new stuff not yet
70
+ released.
71
+
72
+ We also have a [IRC (gitter)](https://gitter.im/ruby-concurrency/concurrent-ruby).
73
+
74
+ ### Versioning
75
+
76
+ * `concurrent-ruby` uses [Semantic Versioning](http://semver.org/)
77
+ * `concurrent-ruby-ext` has always same version as `concurrent-ruby`
78
+ * `concurrent-ruby-edge` will always be 0.y.z therefore following
79
+ [point 4](http://semver.org/#spec-item-4) applies *"Major version zero
80
+ (0.y.z) is for initial development. Anything may change at any time. The
81
+ public API should not be considered stable."* However we additionally use
82
+ following rules:
83
+ * Minor version increment means incompatible changes were made
84
+ * Patch version increment means only compatible changes were made
85
+
86
+
87
+ #### General-purpose Concurrency Abstractions
88
+
89
+ * [Async](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Async.html):
90
+ A mixin module that provides simple asynchronous behavior to a class. Loosely based on Erlang's
91
+ [gen_server](http://www.erlang.org/doc/man/gen_server.html).
92
+ * [ScheduledTask](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ScheduledTask.html):
93
+ Like a Future scheduled for a specific future time.
94
+ * [TimerTask](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/TimerTask.html):
95
+ A Thread that periodically wakes up to perform work at regular intervals.
96
+ * [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html):
97
+ Unified implementation of futures and promises which combines features of previous `Future`,
98
+ `Promise`, `IVar`, `Event`, `dataflow`, `Delay`, and (partially) `TimerTask` into a single
99
+ framework. It extensively uses the new synchronization layer to make all the features
100
+ **non-blocking** and **lock-free**, with the exception of obviously blocking operations like
101
+ `#wait`, `#value`. It also offers better performance.
102
+
103
+ #### Thread-safe Value Objects, Structures, and Collections
104
+
105
+ Collection classes that were originally part of the (deprecated) `thread_safe` gem:
106
+
107
+ * [Array](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Array.html) A thread-safe
108
+ subclass of Ruby's standard [Array](http://ruby-doc.org/core/Array.html).
109
+ * [Hash](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Hash.html) A thread-safe
110
+ subclass of Ruby's standard [Hash](http://ruby-doc.org/core/Hash.html).
111
+ * [Set](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Set.html) A thread-safe
112
+ subclass of Ruby's standard [Set](http://ruby-doc.org/stdlib-2.4.0/libdoc/set/rdoc/Set.html).
113
+ * [Map](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Map.html) A hash-like object
114
+ that should have much better performance characteristics, especially under high concurrency,
115
+ than `Concurrent::Hash`.
116
+ * [Tuple](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Tuple.html) A fixed size
117
+ array with volatile (synchronized, thread safe) getters/setters.
118
+
119
+ Value objects inspired by other languages:
120
+
121
+ * [Maybe](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Maybe.html) A thread-safe,
122
+ immutable object representing an optional value, based on
123
+ [Haskell Data.Maybe](https://hackage.haskell.org/package/base-4.2.0.1/docs/Data-Maybe.html).
124
+
125
+ Structure classes derived from Ruby's [Struct](http://ruby-doc.org/core/Struct.html):
126
+
127
+ * [ImmutableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ImmutableStruct.html)
128
+ Immutable struct where values are set at construction and cannot be changed later.
129
+ * [MutableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/MutableStruct.html)
130
+ Synchronized, mutable struct where values can be safely changed at any time.
131
+ * [SettableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/SettableStruct.html)
132
+ Synchronized, write-once struct where values can be set at most once, either at construction
133
+ or any time thereafter.
134
+
135
+ Thread-safe variables:
136
+
137
+ * [Agent](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Agent.html): A way to
138
+ manage shared, mutable, *asynchronous*, independent state. Based on Clojure's
139
+ [Agent](http://clojure.org/agents).
140
+ * [Atom](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Atom.html): A way to manage
141
+ shared, mutable, *synchronous*, independent state. Based on Clojure's
142
+ [Atom](http://clojure.org/atoms).
143
+ * [AtomicBoolean](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicBoolean.html)
144
+ A boolean value that can be updated atomically.
145
+ * [AtomicFixnum](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicFixnum.html)
146
+ A numeric value that can be updated atomically.
147
+ * [AtomicReference](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicReference.html)
148
+ An object reference that may be updated atomically.
149
+ * [Exchanger](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Exchanger.html)
150
+ A synchronization point at which threads can pair and swap elements within pairs. Based on
151
+ Java's [Exchanger](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Exchanger.html).
152
+ * [MVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/MVar.html) A synchronized
153
+ single element container. Based on Haskell's
154
+ [MVar](https://hackage.haskell.org/package/base-4.8.1.0/docs/Control-Concurrent-MVar.html) and
155
+ Scala's [MVar](http://docs.typelevel.org/api/scalaz/nightly/index.html#scalaz.concurrent.MVar$).
156
+ * [ThreadLocalVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ThreadLocalVar.html)
157
+ A variable where the value is different for each thread.
158
+ * [TVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/TVar.html) A transactional
159
+ variable implementing software transactional memory (STM). Based on Clojure's
160
+ [Ref](http://clojure.org/refs).
161
+
162
+ #### Java-inspired ThreadPools and Other Executors
163
+
164
+ * See the [thread pool](http://ruby-concurrency.github.io/concurrent-ruby/master/file.thread_pools.html)
165
+ overview, which also contains a list of other Executors available.
166
+
167
+ #### Thread Synchronization Classes and Algorithms
168
+
169
+ * [CountDownLatch](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/CountDownLatch.html)
170
+ A synchronization object that allows one thread to wait on multiple other threads.
171
+ * [CyclicBarrier](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/CyclicBarrier.html)
172
+ A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.
173
+ * [Event](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Event.html) Old school
174
+ kernel-style event.
175
+ * [ReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ReadWriteLock.html)
176
+ A lock that supports multiple readers but only one writer.
177
+ * [ReentrantReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ReentrantReadWriteLock.html)
178
+ A read/write lock with reentrant and upgrade features.
179
+ * [Semaphore](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Semaphore.html)
180
+ A counting-based locking mechanism that uses permits.
181
+ * [AtomicMarkableReference](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicMarkableReference.html)
182
+
183
+ #### Deprecated
184
+
185
+ Deprecated features are still available and bugs are being fixed, but new features will not be added.
186
+
187
+ * ~~[Future](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Future.html):
188
+ An asynchronous operation that produces a value.~~ Replaced by
189
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
190
+ * ~~[.dataflow](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent.html#dataflow-class_method):
191
+ Built on Futures, Dataflow allows you to create a task that will be scheduled when all of
192
+ its data dependencies are available.~~ Replaced by
193
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
194
+ * ~~[Promise](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promise.html): Similar
195
+ to Futures, with more features.~~ Replaced by
196
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
197
+ * ~~[Delay](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Delay.html) Lazy evaluation
198
+ of a block yielding an immutable result. Based on Clojure's
199
+ [delay](https://clojuredocs.org/clojure.core/delay).~~ Replaced by
200
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
201
+ * ~~[IVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/IVar.html) Similar to a
202
+ "future" but can be manually assigned once, after which it becomes immutable.~~ Replaced by
203
+ [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
204
+
205
+ ### Edge Features
206
+
207
+ These are available in the `concurrent-ruby-edge` companion gem.
208
+
209
+ These features are under active development and may change frequently. They are expected not to
210
+ keep backward compatibility (there may also lack tests and documentation). Semantic versions will
211
+ be obeyed though. Features developed in `concurrent-ruby-edge` are expected to move to
212
+ `concurrent-ruby` when final.
213
+
214
+ * [Actor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Actor.html): Implements
215
+ the Actor Model, where concurrent actors exchange messages.
216
+ *Status: Partial documentation and tests; depends on new future/promise framework; stability is good.*
217
+ * [Channel](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Channel.html):
218
+ Communicating Sequential Processes ([CSP](https://en.wikipedia.org/wiki/Communicating_sequential_processes)).
219
+ Functionally equivalent to Go [channels](https://tour.golang.org/concurrency/2) with additional
220
+ inspiration from Clojure [core.async](https://clojure.github.io/core.async/).
221
+ *Status: Partial documentation and tests.*
222
+ * [LazyRegister](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/LazyRegister.html)
223
+ * [LockFreeLinkedSet](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Edge/LockFreeLinkedSet.html)
224
+ *Status: will be moved to core soon.*
225
+ * [LockFreeStack](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/LockFreeStack.html)
226
+ *Status: missing documentation and tests.*
227
+ * [Promises::Channel](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises/Channel.html)
228
+ A first in first out channel that accepts messages with push family of methods and returns
229
+ messages with pop family of methods.
230
+ Pop and push operations can be represented as futures, see `#pop_op` and `#push_op`.
231
+ The capacity of the channel can be limited to support back pressure, use capacity option in `#initialize`.
232
+ `#pop` method blocks ans `#pop_op` returns pending future if there is no message in the channel.
233
+ If the capacity is limited the `#push` method blocks and `#push_op` returns pending future.
234
+ * [Cancellation](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Cancellation.html)
235
+ The Cancellation abstraction provides cooperative cancellation.
236
+
237
+ The standard methods `Thread#raise` of `Thread#kill` available in Ruby
238
+ are very dangerous (see linked the blog posts bellow).
239
+ Therefore concurrent-ruby provides an alternative.
240
+
241
+ * <https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/>
242
+ * <http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/>
243
+ * <http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html>
244
+
245
+ It provides an object which represents a task which can be executed,
246
+ the task has to get the reference to the object and periodically cooperatively check that it is not cancelled.
247
+ Good practices to make tasks cancellable:
248
+ * check cancellation every cycle of a loop which does significant work,
249
+ * do all blocking actions in a loop with a timeout then on timeout check cancellation
250
+ and if ok block again with the timeout
251
+ * [Throttle](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Throttle.html)
252
+ A tool managing concurrency level of tasks.
253
+ * [ErlangActor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ErlangActor.html)
254
+ Actor implementation which precisely matches Erlang actor behaviour.
255
+ Requires at least Ruby 2.1 otherwise it's not loaded.
256
+ * [WrappingExecutor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/WrappingExecutor.html)
257
+ A delegating executor which modifies each task before the task is given to
258
+ the target executor it delegates to.
259
+
260
+ ## Supported Ruby versions
261
+
262
+ * MRI 2.2 and above
263
+ * Latest JRuby 9000
264
+ * Latest TruffleRuby
265
+
266
+ The legacy support for Rubinius is kept for the moment but it is no longer maintained and is liable to be removed. If you would like to help
267
+ please respond to [#739](https://github.com/ruby-concurrency/concurrent-ruby/issues/739).
268
+
269
+ ## Usage
270
+
271
+ Everything within this gem can be loaded simply by requiring it:
272
+
273
+ ```ruby
274
+ require 'concurrent'
275
+ ```
276
+
277
+ *Requiring only specific abstractions from Concurrent Ruby is not yet supported.*
278
+
279
+ To use the tools in the Edge gem it must be required separately:
280
+
281
+ ```ruby
282
+ require 'concurrent-edge'
283
+ ```
284
+
285
+ If the library does not behave as expected, `Concurrent.use_stdlib_logger(Logger::DEBUG)` could
286
+ help to reveal the problem.
287
+
288
+ ## Installation
289
+
290
+ ```shell
291
+ gem install concurrent-ruby
292
+ ```
293
+
294
+ or add the following line to Gemfile:
295
+
296
+ ```ruby
297
+ gem 'concurrent-ruby', require: 'concurrent'
298
+ ```
299
+
300
+ and run `bundle install` from your shell.
301
+
302
+ ### Edge Gem Installation
303
+
304
+ The Edge gem must be installed separately from the core gem:
305
+
306
+ ```shell
307
+ gem install concurrent-ruby-edge
308
+ ```
309
+
310
+ or add the following line to Gemfile:
311
+
312
+ ```ruby
313
+ gem 'concurrent-ruby-edge', require: 'concurrent-edge'
314
+ ```
315
+
316
+ and run `bundle install` from your shell.
317
+
318
+
319
+ ### C Extensions for MRI
320
+
321
+ Potential performance improvements may be achieved under MRI by installing optional C extensions.
322
+ To minimise installation errors the C extensions are available in the `concurrent-ruby-ext`
323
+ extension gem. `concurrent-ruby` and `concurrent-ruby-ext` are always released together with same
324
+ version. Simply install the extension gem too:
325
+
326
+ ```ruby
327
+ gem install concurrent-ruby-ext
328
+ ```
329
+
330
+ or add the following line to Gemfile:
331
+
332
+ ```ruby
333
+ gem 'concurrent-ruby-ext'
334
+ ```
335
+
336
+ and run `bundle install` from your shell.
337
+
338
+ In code it is only necessary to
339
+
340
+ ```ruby
341
+ require 'concurrent'
342
+ ```
343
+
344
+ The `concurrent-ruby` gem will automatically detect the presence of the `concurrent-ruby-ext` gem
345
+ and load the appropriate C extensions.
346
+
347
+ #### Note For gem developers
348
+
349
+ No gems should depend on `concurrent-ruby-ext`. Doing so will force C extensions on your users. The
350
+ best practice is to depend on `concurrent-ruby` and let users to decide if they want C extensions.
351
+
352
+ ## Building the gem
353
+
354
+ ### Requirements
355
+
356
+ * Recent CRuby
357
+ * JRuby, `rbenv install jruby-9.2.17.0`
358
+ * Set env variable `CONCURRENT_JRUBY_HOME` to point to it, e.g. `/usr/local/opt/rbenv/versions/jruby-9.2.17.0`
359
+ * Install Docker, required for Windows builds
360
+
361
+ ### Publishing the Gem
362
+
363
+ * Update `version.rb`
364
+ * Update the CHANGELOG
365
+ * Update the Yard documentation
366
+ - Add the new version to `docs-source/signpost.md`. Needs to be done only if there are visible changes in the
367
+ documentation.
368
+ - Run `bundle exec rake yard` to update the master documentation and signpost.
369
+ - Run `bundle exec rake yard:<new-version>` to add or update the documentation of the new version.
370
+ * Commit (and push) the changes.
371
+ * Use `be rake release` to release the gem. It consists
372
+ of `['release:checks', 'release:build', 'release:test', 'release:publish']` steps. It will ask at the end before
373
+ publishing anything. Steps can also be executed individually.
374
+
375
+ ## Maintainers
376
+
377
+ * [Chris Seaton](https://github.com/chrisseaton) — Lead maintainer, point-of-contact.
378
+ * [Benoit Daloze](https://github.com/eregon) — If Chris is not available Benoit can help.
379
+
380
+ ### Special Thanks to
381
+
382
+ * [Jerry D'Antonio](https://github.com/jdantonio) for creating the gem
383
+ * [Brian Durand](https://github.com/bdurand) for the `ref` gem
384
+ * [Charles Oliver Nutter](https://github.com/headius) for the `atomic` and `thread_safe` gems
385
+ * [thedarkone](https://github.com/thedarkone) for the `thread_safe` gem
386
+
387
+ to the past maintainers
388
+
389
+ * [Petr Chalupa](https://github.com/pitr-ch)
390
+ * [Michele Della Torre](https://github.com/mighe)
391
+ * [Paweł Obrok](https://github.com/obrok)
392
+ * [Lucas Allan](https://github.com/lucasallan)
393
+
394
+ and to [Ruby Association](https://www.ruby.or.jp/en/) for sponsoring a project
395
+ ["Enhancing Ruby’s concurrency tooling"](https://www.ruby.or.jp/en/news/20181106) in 2018.
396
+
397
+ ## License and Copyright
398
+
399
+ *Concurrent Ruby* is free software released under the
400
+ [MIT License](http://www.opensource.org/licenses/MIT).
401
+
402
+ The *Concurrent Ruby* [logo](https://raw.githubusercontent.com/ruby-concurrency/concurrent-ruby/master/docs-source/logo/concurrent-ruby-logo-300x300.png) was
403
+ designed by [David Jones](https://twitter.com/zombyboy). It is Copyright &copy; 2014
404
+ [Jerry D'Antonio](https://twitter.com/jerrydantonio). All Rights Reserved.