concurrent-ruby/README.md

405 lines
22 KiB
Markdown
Raw Permalink Normal View History

2014-03-05 02:37:46 +00:00
# Concurrent Ruby
[![Gem Version](https://badge.fury.io/rb/concurrent-ruby.svg)](http://badge.fury.io/rb/concurrent-ruby)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
2015-07-16 21:39:13 +00:00
[![Gitter chat](https://img.shields.io/badge/IRC%20(gitter)-devs%20%26%20users-brightgreen.svg)](https://gitter.im/ruby-concurrency/concurrent-ruby)
2013-07-23 12:18:51 +00:00
2016-11-05 21:22:25 +00:00
Modern concurrency tools for Ruby. Inspired by
[Erlang](http://www.erlang.org/doc/reference_manual/processes.html),
[Clojure](http://clojure.org/concurrent_programming),
[Scala](http://akka.io/),
[Haskell](http://www.haskell.org/haskellwiki/Applications_and_libraries/Concurrency_and_parallelism#Concurrent_Haskell),
[F#](http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx),
[C#](http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx),
[Java](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html),
and classic concurrency patterns.
2018-08-10 14:33:30 +00:00
<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;" />
2016-11-05 21:22:25 +00:00
The design goals of this gem are:
2017-04-17 11:32:01 +00:00
* Be an 'unopinionated' toolbox that provides useful utilities without debating which is better
or why
2017-03-20 13:49:22 +00:00
* Remain free of external gem dependencies
* Stay true to the spirit of the languages providing inspiration
* But implement in a way that makes sense for Ruby
* Keep the semantics as idiomatic Ruby as possible
* Support features that make sense in Ruby
* Exclude features that don't make sense in Ruby
* Be small, lean, and loosely coupled
2017-04-17 11:32:01 +00:00
* Thread-safety
* Backward compatibility
2018-07-06 16:33:42 +00:00
## Contributing
2017-04-17 11:32:01 +00:00
**This gem depends on
[contributions](https://github.com/ruby-concurrency/concurrent-ruby/graphs/contributors) and we
appreciate your help. Would you like to contribute? Great! Have a look at
2018-07-12 19:13:26 +00:00
[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.
2018-07-06 16:33:42 +00:00
Add CodeTriage badge to ruby-concurrency/concurrent-ruby Adds a badge showing the number of people helping this repo on CodeTriage. [![Open Source Helpers](https://www.codetriage.com/ruby-concurrency/concurrent-ruby/badges/users.svg)](https://www.codetriage.com/ruby-concurrency/concurrent-ruby) ## What is CodeTriage? CodeTriage is an Open Source app that is designed to make contributing to Open Source projects easier. It works by sending subscribers a few open issues in their inbox. If subscribers get busy, there is an algorithm that backs off issue load so they do not get overwhelmed [Read more about the CodeTriage project](https://www.codetriage.com/what). ## Why am I getting this PR? Your project was picked by the human, @schneems. They selected it from the projects submitted to https://www.codetriage.com and hand edited the PR. How did your project get added to [CodeTriage](https://www.codetriage.com/what)? Roughly over 3 years ago, [anildigital](https://github.com/anildigital) added this project to CodeTriage in order to start contributing. Since then, 4 people have subscribed to help this repo. ## What does adding a badge accomplish? Adding a badge invites people to help contribute to your project. It also lets developers know that others are invested in the longterm success and maintainability of the project. You can see an example of a CodeTriage badge on these popular OSS READMEs: - [![Email clients like GMAIL do not render SVG images](https://www.codetriage.com/rails/rails/badges/users.svg)](https://www.codetriage.com/rails/rails) https://github.com/rails/rails - [![Email clients like GMAIL do not render SVG images](https://www.codetriage.com/crystal-lang/crystal/badges/users.svg)](https://www.codetriage.com/crystal-lang/crystal) https://github.com/crystal-lang/crystal ## Have a question or comment? While I am a bot, this PR was manually reviewed and monitored by a human - @schneems. My job is writing commit messages and handling PR logistics. If you have any questions, you can reply back to this PR and they will be answered by @schneems. If you do not want a badge right now, no worries, close the PR, you will not hear from me again. Thanks for making your project Open Source! Any feedback is greatly appreciated.
2019-06-05 19:39:09 +00:00
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)
## Thread Safety
2017-03-20 13:49:22 +00:00
*Concurrent Ruby makes one of the strongest thread safety guarantees of any Ruby concurrency
2019-02-03 08:16:13 +00:00
library, providing consistent behavior and guarantees on all four of the main Ruby interpreters
2018-12-06 14:46:35 +00:00
(MRI/CRuby, JRuby, Rubinius, TruffleRuby).*
2017-03-20 13:49:22 +00:00
Every abstraction in this library is thread safe. Specific thread safety guarantees are documented
with each abstraction.
2017-03-20 13:49:22 +00:00
It is critical to remember, however, that Ruby is a language of mutable references. *No*
concurrency library for Ruby can ever prevent the user from making thread safety mistakes (such as
sharing a mutable object between threads and modifying it on both threads) or from creating
deadlocks through incorrect use of locks. All the library can do is provide safe abstractions which
encourage safe practices. Concurrent Ruby provides more safe concurrency abstractions than any
other Ruby library, many of which support the mantra of
["Do not communicate by sharing memory; instead, share memory by communicating"](https://blog.golang.org/share-memory-by-communicating).
Concurrent Ruby is also the only Ruby library which provides a full suite of thread safe and
immutable variable types and data structures.
We've also initiated discussion to document [memory model](docs-source/synchronization.md) of Ruby which
2018-12-06 14:46:35 +00:00
would provide consistent behaviour and guarantees on all four of the main Ruby interpreters
2017-04-17 11:32:01 +00:00
(MRI/CRuby, JRuby, Rubinius, TruffleRuby).
## Features & Documentation
2017-03-20 13:49:22 +00:00
**The primary site for documentation is the automatically generated
2018-08-10 14:40:56 +00:00
[API documentation](http://ruby-concurrency.github.io/concurrent-ruby/index.html) which is up to
2017-03-20 13:49:22 +00:00
date with latest release.** This readme matches the master so may contain new stuff not yet
released.
2017-04-17 11:32:01 +00:00
We also have a [IRC (gitter)](https://gitter.im/ruby-concurrency/concurrent-ruby).
### Versioning
* `concurrent-ruby` uses [Semantic Versioning](http://semver.org/)
* `concurrent-ruby-ext` has always same version as `concurrent-ruby`
* `concurrent-ruby-edge` will always be 0.y.z therefore following
[point 4](http://semver.org/#spec-item-4) applies *"Major version zero
(0.y.z) is for initial development. Anything may change at any time. The
public API should not be considered stable."* However we additionally use
following rules:
* Minor version increment means incompatible changes were made
* Patch version increment means only compatible changes were made
2015-06-02 18:36:39 +00:00
#### General-purpose Concurrency Abstractions
2018-08-14 03:25:56 +00:00
* [Async](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Async.html):
2017-03-20 13:49:22 +00:00
A mixin module that provides simple asynchronous behavior to a class. Loosely based on Erlang's
[gen_server](http://www.erlang.org/doc/man/gen_server.html).
2018-08-14 03:25:56 +00:00
* [ScheduledTask](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ScheduledTask.html):
2017-03-20 13:49:22 +00:00
Like a Future scheduled for a specific future time.
2018-08-14 03:25:56 +00:00
* [TimerTask](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/TimerTask.html):
2017-03-20 13:49:22 +00:00
A Thread that periodically wakes up to perform work at regular intervals.
* [Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html):
2017-03-20 13:49:22 +00:00
Unified implementation of futures and promises which combines features of previous `Future`,
`Promise`, `IVar`, `Event`, `dataflow`, `Delay`, and (partially) `TimerTask` into a single
framework. It extensively uses the new synchronization layer to make all the features
**non-blocking** and **lock-free**, with the exception of obviously blocking operations like
`#wait`, `#value`. It also offers better performance.
2015-08-10 14:49:34 +00:00
#### Thread-safe Value Objects, Structures, and Collections
2015-07-28 11:52:35 +00:00
2015-08-10 14:49:34 +00:00
Collection classes that were originally part of the (deprecated) `thread_safe` gem:
2015-07-28 11:52:35 +00:00
2018-08-14 03:25:56 +00:00
* [Array](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Array.html) A thread-safe
subclass of Ruby's standard [Array](http://ruby-doc.org/core/Array.html).
2018-08-14 03:25:56 +00:00
* [Hash](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Hash.html) A thread-safe
subclass of Ruby's standard [Hash](http://ruby-doc.org/core/Hash.html).
2018-08-14 03:25:56 +00:00
* [Set](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Set.html) A thread-safe
2017-03-20 13:49:22 +00:00
subclass of Ruby's standard [Set](http://ruby-doc.org/stdlib-2.4.0/libdoc/set/rdoc/Set.html).
2018-08-14 03:25:56 +00:00
* [Map](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Map.html) A hash-like object
2017-03-20 13:49:22 +00:00
that should have much better performance characteristics, especially under high concurrency,
than `Concurrent::Hash`.
2018-08-14 03:25:56 +00:00
* [Tuple](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Tuple.html) A fixed size
2017-03-20 13:49:22 +00:00
array with volatile (synchronized, thread safe) getters/setters.
2015-07-28 11:52:35 +00:00
2015-08-10 14:49:34 +00:00
Value objects inspired by other languages:
2018-08-14 03:25:56 +00:00
* [Maybe](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Maybe.html) A thread-safe,
2017-03-20 13:49:22 +00:00
immutable object representing an optional value, based on
[Haskell Data.Maybe](https://hackage.haskell.org/package/base-4.2.0.1/docs/Data-Maybe.html).
2015-06-02 18:36:39 +00:00
Structure classes derived from Ruby's [Struct](http://ruby-doc.org/core/Struct.html):
2018-08-14 03:25:56 +00:00
* [ImmutableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ImmutableStruct.html)
2017-03-20 13:49:22 +00:00
Immutable struct where values are set at construction and cannot be changed later.
2018-08-14 03:25:56 +00:00
* [MutableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/MutableStruct.html)
2017-03-20 13:49:22 +00:00
Synchronized, mutable struct where values can be safely changed at any time.
2018-08-14 03:25:56 +00:00
* [SettableStruct](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/SettableStruct.html)
2017-03-20 13:49:22 +00:00
Synchronized, write-once struct where values can be set at most once, either at construction
or any time thereafter.
2015-08-10 14:49:34 +00:00
Thread-safe variables:
2018-08-14 03:25:56 +00:00
* [Agent](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Agent.html): A way to
2017-03-20 13:49:22 +00:00
manage shared, mutable, *asynchronous*, independent state. Based on Clojure's
[Agent](http://clojure.org/agents).
2018-08-14 03:25:56 +00:00
* [Atom](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Atom.html): A way to manage
2017-03-20 13:49:22 +00:00
shared, mutable, *synchronous*, independent state. Based on Clojure's
[Atom](http://clojure.org/atoms).
2018-08-14 03:25:56 +00:00
* [AtomicBoolean](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicBoolean.html)
2017-03-20 13:49:22 +00:00
A boolean value that can be updated atomically.
2018-08-14 03:25:56 +00:00
* [AtomicFixnum](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicFixnum.html)
2017-03-20 13:49:22 +00:00
A numeric value that can be updated atomically.
2018-08-28 18:28:01 +00:00
* [AtomicReference](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicReference.html)
2017-03-20 13:49:22 +00:00
An object reference that may be updated atomically.
2018-08-14 03:25:56 +00:00
* [Exchanger](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Exchanger.html)
2017-03-20 13:49:22 +00:00
A synchronization point at which threads can pair and swap elements within pairs. Based on
Java's [Exchanger](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Exchanger.html).
2018-08-14 03:25:56 +00:00
* [MVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/MVar.html) A synchronized
2017-03-20 13:49:22 +00:00
single element container. Based on Haskell's
[MVar](https://hackage.haskell.org/package/base-4.8.1.0/docs/Control-Concurrent-MVar.html) and
Scala's [MVar](http://docs.typelevel.org/api/scalaz/nightly/index.html#scalaz.concurrent.MVar$).
2018-08-14 03:25:56 +00:00
* [ThreadLocalVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ThreadLocalVar.html)
2017-03-20 13:49:22 +00:00
A variable where the value is different for each thread.
2018-08-14 03:25:56 +00:00
* [TVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/TVar.html) A transactional
2017-03-20 13:49:22 +00:00
variable implementing software transactional memory (STM). Based on Clojure's
[Ref](http://clojure.org/refs).
2015-06-02 18:36:39 +00:00
#### Java-inspired ThreadPools and Other Executors
2018-08-14 03:25:56 +00:00
* See the [thread pool](http://ruby-concurrency.github.io/concurrent-ruby/master/file.thread_pools.html)
2017-03-20 13:49:22 +00:00
overview, which also contains a list of other Executors available.
2015-06-02 18:36:39 +00:00
#### Thread Synchronization Classes and Algorithms
2014-12-29 13:47:09 +00:00
2018-08-14 03:25:56 +00:00
* [CountDownLatch](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/CountDownLatch.html)
2017-03-20 13:49:22 +00:00
A synchronization object that allows one thread to wait on multiple other threads.
2018-08-14 03:25:56 +00:00
* [CyclicBarrier](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/CyclicBarrier.html)
2017-03-20 13:49:22 +00:00
A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point.
2018-08-14 03:25:56 +00:00
* [Event](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Event.html) Old school
2017-03-20 13:49:22 +00:00
kernel-style event.
2018-08-14 03:25:56 +00:00
* [ReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ReadWriteLock.html)
2017-03-20 13:49:22 +00:00
A lock that supports multiple readers but only one writer.
2018-08-14 03:25:56 +00:00
* [ReentrantReadWriteLock](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ReentrantReadWriteLock.html)
2017-03-20 13:49:22 +00:00
A read/write lock with reentrant and upgrade features.
2018-08-14 03:25:56 +00:00
* [Semaphore](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Semaphore.html)
2017-03-20 13:49:22 +00:00
A counting-based locking mechanism that uses permits.
2018-08-28 18:28:01 +00:00
* [AtomicMarkableReference](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/AtomicMarkableReference.html)
2017-03-20 13:49:22 +00:00
#### Deprecated
2018-07-12 19:15:56 +00:00
Deprecated features are still available and bugs are being fixed, but new features will not be added.
2017-03-20 13:49:22 +00:00
2018-08-14 03:25:56 +00:00
* ~~[Future](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Future.html):
2018-07-12 19:15:56 +00:00
An asynchronous operation that produces a value.~~ Replaced by
[Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
* ~~[.dataflow](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent.html#dataflow-class_method):
2017-03-20 13:49:22 +00:00
Built on Futures, Dataflow allows you to create a task that will be scheduled when all of
2018-07-12 19:15:56 +00:00
its data dependencies are available.~~ Replaced by
[Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
2018-08-14 03:25:56 +00:00
* ~~[Promise](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promise.html): Similar
2018-07-12 19:15:56 +00:00
to Futures, with more features.~~ Replaced by
[Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
2018-08-14 03:25:56 +00:00
* ~~[Delay](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Delay.html) Lazy evaluation
2017-03-20 13:49:22 +00:00
of a block yielding an immutable result. Based on Clojure's
2018-07-12 19:15:56 +00:00
[delay](https://clojuredocs.org/clojure.core/delay).~~ Replaced by
[Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
2018-08-14 03:25:56 +00:00
* ~~[IVar](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/IVar.html) Similar to a
2018-07-12 19:15:56 +00:00
"future" but can be manually assigned once, after which it becomes immutable.~~ Replaced by
[Promises](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises.html).
2017-03-20 13:49:22 +00:00
2015-06-02 18:36:39 +00:00
### Edge Features
2015-08-18 16:45:05 +00:00
These are available in the `concurrent-ruby-edge` companion gem.
2015-04-08 09:24:44 +00:00
These features are under active development and may change frequently. They are expected not to
keep backward compatibility (there may also lack tests and documentation). Semantic versions will
2017-03-20 13:49:22 +00:00
be obeyed though. Features developed in `concurrent-ruby-edge` are expected to move to
`concurrent-ruby` when final.
2018-08-14 03:25:56 +00:00
* [Actor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Actor.html): Implements
2017-03-20 13:49:22 +00:00
the Actor Model, where concurrent actors exchange messages.
2017-04-17 11:32:01 +00:00
*Status: Partial documentation and tests; depends on new future/promise framework; stability is good.*
2018-08-14 03:25:56 +00:00
* [Channel](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Channel.html):
2017-03-20 13:49:22 +00:00
Communicating Sequential Processes ([CSP](https://en.wikipedia.org/wiki/Communicating_sequential_processes)).
Functionally equivalent to Go [channels](https://tour.golang.org/concurrency/2) with additional
inspiration from Clojure [core.async](https://clojure.github.io/core.async/).
2017-04-17 11:32:01 +00:00
*Status: Partial documentation and tests.*
2018-08-14 03:25:56 +00:00
* [LazyRegister](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/LazyRegister.html)
* [LockFreeLinkedSet](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Edge/LockFreeLinkedSet.html)
2017-04-17 11:32:01 +00:00
*Status: will be moved to core soon.*
2018-08-14 03:25:56 +00:00
* [LockFreeStack](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/LockFreeStack.html)
2017-04-17 11:32:01 +00:00
*Status: missing documentation and tests.*
2019-02-10 18:33:11 +00:00
* [Promises::Channel](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Promises/Channel.html)
A first in first out channel that accepts messages with push family of methods and returns
messages with pop family of methods.
2019-03-02 14:29:41 +00:00
Pop and push operations can be represented as futures, see `#pop_op` and `#push_op`.
The capacity of the channel can be limited to support back pressure, use capacity option in `#initialize`.
`#pop` method blocks ans `#pop_op` returns pending future if there is no message in the channel.
If the capacity is limited the `#push` method blocks and `#push_op` returns pending future.
2019-02-10 18:33:11 +00:00
* [Cancellation](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Cancellation.html)
The Cancellation abstraction provides cooperative cancellation.
The standard methods `Thread#raise` of `Thread#kill` available in Ruby
are very dangerous (see linked the blog posts bellow).
Therefore concurrent-ruby provides an alternative.
* <https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/>
* <http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/>
* <http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html>
It provides an object which represents a task which can be executed,
the task has to get the reference to the object and periodically cooperatively check that it is not cancelled.
Good practices to make tasks cancellable:
* check cancellation every cycle of a loop which does significant work,
* do all blocking actions in a loop with a timeout then on timeout check cancellation
and if ok block again with the timeout
* [Throttle](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/Throttle.html)
A tool managing concurrency level of tasks.
* [ErlangActor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ErlangActor.html)
2019-03-11 08:58:27 +00:00
Actor implementation which precisely matches Erlang actor behaviour.
Requires at least Ruby 2.1 otherwise it's not loaded.
2020-01-19 17:45:06 +00:00
* [WrappingExecutor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/WrappingExecutor.html)
A delegating executor which modifies each task before the task is given to
the target executor it delegates to.
2015-06-07 16:35:48 +00:00
2018-07-07 19:02:17 +00:00
## Supported Ruby versions
* MRI 2.2 and above
* Latest JRuby 9000
* Latest TruffleRuby
2018-11-01 11:52:31 +00:00
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
2018-07-07 20:33:20 +00:00
please respond to [#739](https://github.com/ruby-concurrency/concurrent-ruby/issues/739).
## Usage
2015-08-18 16:45:05 +00:00
Everything within this gem can be loaded simply by requiring it:
```ruby
require 'concurrent'
```
2017-04-17 11:32:01 +00:00
*Requiring only specific abstractions from Concurrent Ruby is not yet supported.*
2015-08-18 16:45:05 +00:00
To use the tools in the Edge gem it must be required separately:
```ruby
2015-08-18 16:45:05 +00:00
require 'concurrent-edge'
```
2017-03-20 13:49:22 +00:00
If the library does not behave as expected, `Concurrent.use_stdlib_logger(Logger::DEBUG)` could
help to reveal the problem.
2015-06-07 09:05:54 +00:00
## Installation
```shell
gem install concurrent-ruby
```
or add the following line to Gemfile:
```ruby
2015-12-10 12:13:30 +00:00
gem 'concurrent-ruby', require: 'concurrent'
```
and run `bundle install` from your shell.
2015-08-18 16:45:05 +00:00
### Edge Gem Installation
The Edge gem must be installed separately from the core gem:
```shell
gem install concurrent-ruby-edge
```
or add the following line to Gemfile:
```ruby
2015-12-10 12:13:30 +00:00
gem 'concurrent-ruby-edge', require: 'concurrent-edge'
2015-08-18 16:45:05 +00:00
```
and run `bundle install` from your shell.
### C Extensions for MRI
Potential performance improvements may be achieved under MRI by installing optional C extensions.
2017-03-20 13:49:22 +00:00
To minimise installation errors the C extensions are available in the `concurrent-ruby-ext`
extension gem. `concurrent-ruby` and `concurrent-ruby-ext` are always released together with same
version. Simply install the extension gem too:
2014-12-29 14:03:13 +00:00
```ruby
gem install concurrent-ruby-ext
```
or add the following line to Gemfile:
```ruby
gem 'concurrent-ruby-ext'
```
and run `bundle install` from your shell.
In code it is only necessary to
2014-12-29 14:03:13 +00:00
```ruby
require 'concurrent'
```
The `concurrent-ruby` gem will automatically detect the presence of the `concurrent-ruby-ext` gem
and load the appropriate C extensions.
#### Note For gem developers
2017-03-20 13:49:22 +00:00
No gems should depend on `concurrent-ruby-ext`. Doing so will force C extensions on your users. The
best practice is to depend on `concurrent-ruby` and let users to decide if they want C extensions.
2021-06-05 08:17:47 +00:00
## Building the gem
### Requirements
* Recent CRuby
* JRuby, `rbenv install jruby-9.2.17.0`
* Set env variable `CONCURRENT_JRUBY_HOME` to point to it, e.g. `/usr/local/opt/rbenv/versions/jruby-9.2.17.0`
* Install Docker, required for Windows builds
### Publishing the Gem
2022-03-13 18:51:37 +00:00
* Update `version.rb`
2021-06-05 08:17:47 +00:00
* Update the CHANGELOG
* Update the Yard documentation
- Add the new version to `docs-source/signpost.md`. Needs to be done only if there are visible changes in the
documentation.
- Run `bundle exec rake yard` to update the master documentation and signpost.
- Run `bundle exec rake yard:<new-version>` to add or update the documentation of the new version.
* Commit (and push) the changes.
* Use `be rake release` to release the gem. It consists
of `['release:checks', 'release:build', 'release:test', 'release:publish']` steps. It will ask at the end before
publishing anything. Steps can also be executed individually.
## Maintainers
2014-01-20 14:58:42 +00:00
2022-01-31 07:34:41 +00:00
* [Chris Seaton](https://github.com/chrisseaton) — Lead maintainer, point-of-contact.
* [Benoit Daloze](https://github.com/eregon) — If Chris is not available Benoit can help.
2015-07-28 11:52:35 +00:00
2018-07-28 18:52:27 +00:00
### Special Thanks to
2015-07-28 11:52:35 +00:00
2022-01-31 07:34:41 +00:00
* [Jerry D'Antonio](https://github.com/jdantonio) for creating the gem
* [Brian Durand](https://github.com/bdurand) for the `ref` gem
* [Charles Oliver Nutter](https://github.com/headius) for the `atomic` and `thread_safe` gems
* [thedarkone](https://github.com/thedarkone) for the `thread_safe` gem
2021-06-05 08:17:47 +00:00
to the past maintainers
2017-04-17 11:32:01 +00:00
2022-01-31 07:34:41 +00:00
* [Petr Chalupa](https://github.com/pitr-ch)
* [Michele Della Torre](https://github.com/mighe)
* [Paweł Obrok](https://github.com/obrok)
* [Lucas Allan](https://github.com/lucasallan)
2017-04-17 11:32:01 +00:00
2019-03-09 14:14:12 +00:00
and to [Ruby Association](https://www.ruby.or.jp/en/) for sponsoring a project
["Enhancing Rubys concurrency tooling"](https://www.ruby.or.jp/en/news/20181106) in 2018.
2014-01-20 14:58:42 +00:00
## License and Copyright
2017-03-20 13:49:22 +00:00
*Concurrent Ruby* is free software released under the
[MIT License](http://www.opensource.org/licenses/MIT).
2014-03-22 23:52:22 +00:00
2019-02-11 10:12:44 +00:00
The *Concurrent Ruby* [logo](https://raw.githubusercontent.com/ruby-concurrency/concurrent-ruby/master/docs-source/logo/concurrent-ruby-logo-300x300.png) was
2017-03-20 13:49:22 +00:00
designed by [David Jones](https://twitter.com/zombyboy). It is Copyright &copy; 2014
[Jerry D'Antonio](https://twitter.com/jerrydantonio). All Rights Reserved.