aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-02-02 01:42:20 +1030
committerMatthew Draper <matthew@trebex.net>2016-02-02 03:21:03 +1030
commitf836630f8cdf53a06259cc22ac842bbfa6376f65 (patch)
treee870b2cc12783ca8b436bc28ca22a2d9a960306d /activesupport/test
parentf02bd2a92c67f0d4190853521d3580766e829044 (diff)
downloadrails-f836630f8cdf53a06259cc22ac842bbfa6376f65.tar.gz
rails-f836630f8cdf53a06259cc22ac842bbfa6376f65.tar.bz2
rails-f836630f8cdf53a06259cc22ac842bbfa6376f65.zip
After completing a load, give other threads a chance too
While we know no user code is running, we should do as much loading as we can. That way, all the threads will then be able to resume running user code together. Otherwise, only the last arriving thread would get to do its load, and would then return to userspace, leaving the others still blocked.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/share_lock_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb
index 3475ee94cd..12953d99a6 100644
--- a/activesupport/test/share_lock_test.rb
+++ b/activesupport/test/share_lock_test.rb
@@ -270,6 +270,23 @@ class ShareLockTest < ActiveSupport::TestCase
end
end
+ def test_compatible_exclusives_cooperate_to_both_proceed
+ ready = Concurrent::CyclicBarrier.new(2)
+ done = Concurrent::CyclicBarrier.new(2)
+
+ threads = 2.times.map do
+ Thread.new do
+ @lock.sharing do
+ ready.wait
+ @lock.exclusive(purpose: :x, compatible: [:x], after_compatible: [:x]) {}
+ done.wait
+ end
+ end
+ end
+
+ assert_threads_not_stuck threads
+ end
+
def test_in_shared_section_incompatible_non_upgrading_threads_cannot_preempt_upgrading_threads
scratch_pad = []
scratch_pad_mutex = Mutex.new