Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
github.com/ruby-concurrency/concurrent-ruby
Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell, F#, C#, Java, and classic concurrency patterns.
The design goals of this gem are:
This gem depends on
contributions and we
appreciate your help. Would you like to contribute? Great! Have a look at
issues with looking-for-contributor
label. And if you pick something up let us know on the issue.
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.
Concurrent Ruby makes one of the strongest thread safety guarantees of any Ruby concurrency library, providing consistent behavior and guarantees on all three main Ruby interpreters (MRI/CRuby, JRuby, TruffleRuby).
Every abstraction in this library is thread safe. Specific thread safety guarantees are documented with each abstraction.
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". 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 the memory model of Ruby which would provide consistent behaviour and guarantees on all three main Ruby interpreters (MRI/CRuby, JRuby, TruffleRuby).
The primary site for documentation is the automatically generated API documentation which is up to date with latest release. This readme matches the master so may contain new stuff not yet released.
We also have a IRC (gitter).
concurrent-ruby
uses Semantic Versioningconcurrent-ruby-ext
has always same version as concurrent-ruby
concurrent-ruby-edge
will always be 0.y.z therefore following
point 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:
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.Collection classes that were originally part of the (deprecated) thread_safe
gem:
Concurrent::Hash
.Value objects inspired by other languages:
Structure classes derived from Ruby's Struct:
Thread-safe variables:
Deprecated features are still available and bugs are being fixed, but new features will not be added.
These are available in the concurrent-ruby-edge
companion gem.
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
be obeyed though. Features developed in concurrent-ruby-edge
are expected to move to
concurrent-ruby
when final.
Actor: Implements the Actor Model, where concurrent actors exchange messages. Status: Partial documentation and tests; depends on new future/promise framework; stability is good.
Channel: Communicating Sequential Processes (CSP). Functionally equivalent to Go channels with additional inspiration from Clojure core.async. Status: Partial documentation and tests.
LockFreeLinkedSet Status: will be moved to core soon.
LockFreeStack Status: missing documentation and tests.
Promises::Channel
A first in first out channel that accepts messages with push family of methods and returns
messages with pop family of methods.
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.
Cancellation 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.
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:
Throttle A tool managing concurrency level of tasks.
ErlangActor Actor implementation which precisely matches Erlang actor behaviour. Requires at least Ruby 2.1 otherwise it's not loaded.
WrappingExecutor A delegating executor which modifies each task before the task is given to the target executor it delegates to.
Everything within this gem can be loaded simply by requiring it:
require 'concurrent'
You can also require a specific abstraction part of the public documentation since concurrent-ruby 1.2.0, for example:
require 'concurrent/map'
require 'concurrent/atomic/atomic_reference'
require 'concurrent/executor/fixed_thread_pool'
To use the tools in the Edge gem it must be required separately:
require 'concurrent-edge'
If the library does not behave as expected, Concurrent.use_simple_logger(:DEBUG)
could
help to reveal the problem.
gem install concurrent-ruby
or add the following line to Gemfile:
gem 'concurrent-ruby', require: 'concurrent'
and run bundle install
from your shell.
The Edge gem must be installed separately from the core gem:
gem install concurrent-ruby-edge
or add the following line to Gemfile:
gem 'concurrent-ruby-edge', require: 'concurrent-edge'
and run bundle install
from your shell.
Potential performance improvements may be achieved under MRI by installing optional C extensions.
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:
gem install concurrent-ruby-ext
or add the following line to Gemfile:
gem 'concurrent-ruby-ext'
and run bundle install
from your shell.
In code it is only necessary to
require 'concurrent'
The concurrent-ruby
gem will automatically detect the presence of the concurrent-ruby-ext
gem
and load the appropriate C extensions.
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.
rbenv install jruby-9.2.17.0
CONCURRENT_JRUBY_HOME
to point to it, e.g. /usr/local/opt/rbenv/versions/jruby-9.2.17.0
version.rb
docs-source/signpost.md
. Needs to be done only if there are visible changes in the documentation.bundle exec 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.ref
gematomic
and thread_safe
gemsthread_safe
gemto the past maintainers
and to Ruby Association for sponsoring a project "Enhancing Ruby’s concurrency tooling" in 2018.
Concurrent Ruby is free software released under the MIT License.
The Concurrent Ruby logo was designed by David Jones. It is Copyright © 2014 Jerry D'Antonio. All Rights Reserved.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.