Skip to content

Commit

Permalink
Minor updates to align monitor.rb with CRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 31, 2024
1 parent 00c0ab8 commit af1e0b5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/ruby/stdlib/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
# You can freely distribute/modify this library.
#

case RUBY_ENGINE
when 'jruby'
JRuby::Util.load_ext("org.jruby.ext.monitor.MonitorLibrary")
else
require 'monitor.so'
end

#
# In concurrent programming, a monitor is an object or module intended to be
# used safely by more than one thread. The defining characteristic of a
# monitor is that its methods are executed with mutual exclusion. That is, at
# used safely by more than one thread. The defining characteristic of a
# monitor is that its methods are executed with mutual exclusion. That is, at
# each point in time, at most one thread may be executing any of its methods.
# This mutual exclusion greatly simplifies reasoning about the implementation
# of monitors compared to reasoning about parallel code that updates a data
# structure.
#
# You can read more about the general principles on the Wikipedia page for
# Monitors[https://en.wikipedia.org/wiki/Monitor_%28synchronization%29]
# Monitors[https://en.wikipedia.org/wiki/Monitor_%28synchronization%29].
#
# == Examples
#
Expand Down Expand Up @@ -48,7 +55,7 @@
# end
#
# The consumer thread waits for the producer thread to push a line to buf
# while <tt>buf.empty?</tt>. The producer thread (main thread) reads a
# while <tt>buf.empty?</tt>. The producer thread (main thread) reads a
# line from ARGF and pushes it into buf then calls <tt>empty_cond.signal</tt>
# to notify the consumer thread of new data.
#
Expand Down Expand Up @@ -86,14 +93,6 @@
# This Class is implemented as subclass of Array which includes the
# MonitorMixin module.
#

case RUBY_ENGINE
when 'jruby'
JRuby::Util.load_ext("org.jruby.ext.monitor.MonitorLibrary")
else
require 'monitor.so'
end

module MonitorMixin
#
# FIXME: This isn't documented in Nutshell.
Expand Down

0 comments on commit af1e0b5

Please sign in to comment.