Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2cc20dd

Browse files
author
Alex Belozierov
committed
- refactor and fix bug with deinitiallization in PThreadPool
1 parentf2bd619 commit2cc20dd

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

‎PosixDispatch/PThreadPool.swift‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@ class PThreadPool {
1616
privatevarqueue=FifoQueue<Block>()
1717

1818
init(count:Int){
19-
letgroup=PDispatchGroup(count: count)
2019
weakvarpool:PThreadPool?
2120
threads=(0..<count).map{ _in
2221
PThread{
23-
group.leave()
24-
pool?.condition.lock()
25-
whilelet condition= pool?.condition{
26-
condition.wait()
27-
pool?.runloop()
28-
}
22+
guardlet condition= pool?.conditionelse{return}
23+
condition.lock()
24+
condition.wait(while: pool?.runLoop()!=nil)
25+
condition.signal()
26+
condition.unlock()
2927
}
3028
}
3129
pool=self
3230
threads.forEach{ $0.start()}
33-
group.wait()
3431
}
3532

3633
@inlinablevarthreadCount:Int{
@@ -39,7 +36,7 @@ class PThreadPool {
3936

4037
// MARK: - RunLoop
4138

42-
privatefuncrunloop(){
39+
privatefuncrunLoop(){
4340
whilelet block= queue.pop(){
4441
condition.unlock()
4542
block()
@@ -67,4 +64,8 @@ class PThreadPool {
6764
condition.unlock()
6865
}
6966

67+
deinit{
68+
condition.broadcast()
69+
}
70+
7071
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp