Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
467f9ce2
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
467f9ce2
编写于
2月 25, 2019
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed ThreadPool when there are too many inactive threads #4485
上级
c26657ce
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
4 deletion
+44
-4
dbms/src/Common/ThreadPool.cpp
dbms/src/Common/ThreadPool.cpp
+1
-0
dbms/src/Common/ThreadPool.h
dbms/src/Common/ThreadPool.h
+14
-4
dbms/src/Common/tests/CMakeLists.txt
dbms/src/Common/tests/CMakeLists.txt
+3
-0
dbms/src/Common/tests/thread_pool_3.cpp
dbms/src/Common/tests/thread_pool_3.cpp
+26
-0
未找到文件。
dbms/src/Common/ThreadPool.cpp
浏览文件 @
467f9ce2
...
...
@@ -188,6 +188,7 @@ void ThreadPoolImpl<Thread>::worker(typename std::list<Thread>::iterator thread_
if
(
threads
.
size
()
>
scheduled_jobs
+
max_free_threads
)
{
thread_it
->
detach
();
threads
.
erase
(
thread_it
);
job_finished
.
notify_all
();
return
;
...
...
dbms/src/Common/ThreadPool.h
浏览文件 @
467f9ce2
...
...
@@ -134,10 +134,11 @@ public:
template
<
typename
Function
,
typename
...
Args
>
explicit
ThreadFromGlobalPool
(
Function
&&
func
,
Args
&&
...
args
)
{
mutex
=
std
::
make_
unique
<
std
::
mutex
>
();
mutex
=
std
::
make_
shared
<
std
::
mutex
>
();
/// The function object must be copyable, so we wrap lock_guard in shared_ptr.
GlobalThreadPool
::
instance
().
scheduleOrThrow
([
mutex
=
mutex
,
lock
=
std
::
make_shared
<
std
::
lock_guard
<
std
::
mutex
>>
(
*
mutex
),
func
=
std
::
forward
<
Function
>
(
func
),
args
=
std
::
make_tuple
(
std
::
forward
<
Args
>
(
args
)...)]
...
...
@@ -154,7 +155,7 @@ public:
ThreadFromGlobalPool
&
operator
=
(
ThreadFromGlobalPool
&&
rhs
)
{
if
(
mutex
)
if
(
joinable
()
)
std
::
terminate
();
mutex
=
std
::
move
(
rhs
.
mutex
);
return
*
this
;
...
...
@@ -162,25 +163,34 @@ public:
~
ThreadFromGlobalPool
()
{
if
(
mutex
)
if
(
joinable
()
)
std
::
terminate
();
}
void
join
()
{
if
(
!
joinable
())
std
::
terminate
();
{
std
::
lock_guard
lock
(
*
mutex
);
}
mutex
.
reset
();
}
void
detach
()
{
if
(
!
joinable
())
std
::
terminate
();
mutex
.
reset
();
}
bool
joinable
()
const
{
return
static_cast
<
bool
>
(
mutex
);
}
private:
std
::
unique
_ptr
<
std
::
mutex
>
mutex
;
/// Object must be moveable.
std
::
shared
_ptr
<
std
::
mutex
>
mutex
;
/// Object must be moveable.
};
...
...
dbms/src/Common/tests/CMakeLists.txt
浏览文件 @
467f9ce2
...
...
@@ -56,6 +56,9 @@ target_link_libraries (thread_pool PRIVATE clickhouse_common_io)
add_executable
(
thread_pool_2 thread_pool_2.cpp
)
target_link_libraries
(
thread_pool_2 PRIVATE clickhouse_common_io
)
add_executable
(
thread_pool_3 thread_pool_3.cpp
)
target_link_libraries
(
thread_pool_3 PRIVATE clickhouse_common_io
)
add_executable
(
multi_version multi_version.cpp
)
target_link_libraries
(
multi_version PRIVATE clickhouse_common_io
)
add_check
(
multi_version
)
...
...
dbms/src/Common/tests/thread_pool_3.cpp
0 → 100644
浏览文件 @
467f9ce2
#include <atomic>
#include <iostream>
#include <Common/ThreadPool.h>
/// Test for thread self-removal when number of free threads in pool is too large.
/// Just checks that nothing weird happens.
template
<
typename
Pool
>
void
test
()
{
Pool
pool
(
10
,
2
,
10
);
for
(
size_t
i
=
0
;
i
<
10
;
++
i
)
pool
.
schedule
([]{
std
::
cerr
<<
'.'
;
});
pool
.
wait
();
}
int
main
(
int
,
char
**
)
{
test
<
FreeThreadPool
>
();
std
::
cerr
<<
'\n'
;
test
<
ThreadPool
>
();
std
::
cerr
<<
'\n'
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录