Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9f2df785
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9f2df785
编写于
2月 07, 2016
作者:
T
thedarkone
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AS::Conc::ShareLock#yield_shares tests.
上级
3e4a69e5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
107 addition
and
0 deletion
+107
-0
activesupport/test/share_lock_test.rb
activesupport/test/share_lock_test.rb
+107
-0
未找到文件。
activesupport/test/share_lock_test.rb
浏览文件 @
9f2df785
...
@@ -313,6 +313,113 @@ def test_manual_yield
...
@@ -313,6 +313,113 @@ def test_manual_yield
assert_threads_not_stuck
threads
assert_threads_not_stuck
threads
end
end
def
test_manual_incompatible_yield
ready
=
Concurrent
::
CyclicBarrier
.
new
(
2
)
done
=
Concurrent
::
CyclicBarrier
.
new
(
2
)
threads
=
[
Thread
.
new
do
@lock
.
sharing
do
ready
.
wait
@lock
.
exclusive
(
purpose: :x
)
{}
done
.
wait
end
end
,
Thread
.
new
do
@lock
.
sharing
do
ready
.
wait
@lock
.
yield_shares
(
compatible:
[
:y
])
do
done
.
wait
end
end
end
,
]
assert_threads_stuck
threads
ensure
threads
.
each
(
&
:kill
)
if
threads
end
def
test_manual_recursive_yield
ready
=
Concurrent
::
CyclicBarrier
.
new
(
2
)
done
=
Concurrent
::
CyclicBarrier
.
new
(
2
)
do_compatible_nesting
=
Concurrent
::
CountDownLatch
.
new
threads
=
[
Thread
.
new
do
@lock
.
sharing
do
ready
.
wait
@lock
.
exclusive
(
purpose: :x
)
{}
done
.
wait
end
end
,
Thread
.
new
do
@lock
.
sharing
do
ready
.
wait
@lock
.
yield_shares
(
compatible:
[
:y
])
do
do_compatible_nesting
.
wait
@lock
.
sharing
do
@lock
.
yield_shares
(
compatible:
[
:x
,
:y
])
do
done
.
wait
end
end
end
end
end
]
assert_threads_stuck
threads
do_compatible_nesting
.
count_down
assert_threads_not_stuck
threads
end
def
test_manual_recursive_yield_restores_previous_compatible
ready
=
Concurrent
::
CyclicBarrier
.
new
(
2
)
do_nesting
=
Concurrent
::
CountDownLatch
.
new
after_nesting
=
Concurrent
::
CountDownLatch
.
new
incompatible_thread
=
Thread
.
new
do
ready
.
wait
@lock
.
exclusive
(
purpose: :z
)
{}
end
recursive_yield_shares_thread
=
Thread
.
new
do
@lock
.
sharing
do
ready
.
wait
@lock
.
yield_shares
(
compatible:
[
:y
])
do
do_nesting
.
wait
@lock
.
sharing
do
@lock
.
yield_shares
(
compatible:
[
:x
,
:y
])
{}
end
after_nesting
.
wait
end
end
end
assert_threads_stuck
incompatible_thread
do_nesting
.
count_down
assert_threads_stuck
incompatible_thread
compatible_thread
=
Thread
.
new
do
@lock
.
exclusive
(
purpose: :y
)
{}
end
assert_threads_not_stuck
compatible_thread
post_nesting_incompatible_thread
=
Thread
.
new
do
@lock
.
exclusive
(
purpose: :x
)
{}
end
assert_threads_stuck
post_nesting_incompatible_thread
after_nesting
.
count_down
assert_threads_not_stuck
recursive_yield_shares_thread
# post_nesting_incompatible_thread can now proceed
assert_threads_not_stuck
post_nesting_incompatible_thread
# assert_threads_not_stuck can now proceed
assert_threads_not_stuck
incompatible_thread
end
def
test_in_shared_section_incompatible_non_upgrading_threads_cannot_preempt_upgrading_threads
def
test_in_shared_section_incompatible_non_upgrading_threads_cannot_preempt_upgrading_threads
scratch_pad
=
[]
scratch_pad
=
[]
scratch_pad_mutex
=
Mutex
.
new
scratch_pad_mutex
=
Mutex
.
new
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录