From e281f7b6521d43e71fcf428c5dcdceded3d1cdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=93=E3=81=AE=E4=B8=AD=E4=BA=8C=E7=97=85=E3=81=AB?= =?UTF-8?q?=E7=88=86=E7=84=94=E3=82=92=EF=BC=81?= Date: Fri, 15 Jan 2021 12:20:22 +0800 Subject: [PATCH] add debug echo --- Parallel/ThreadTask/ThreadTask.vb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Parallel/ThreadTask/ThreadTask.vb b/Parallel/ThreadTask/ThreadTask.vb index f436b9e..d30ce62 100644 --- a/Parallel/ThreadTask/ThreadTask.vb +++ b/Parallel/ThreadTask/ThreadTask.vb @@ -34,12 +34,21 @@ Public Class ThreadTask(Of TOut) Return -1 End Function + Public Overrides Function ToString() As String + Dim free$ = threads.Where(Function(t) t Is Nothing).Count + Dim running$ = threads.Where(Function(t) t IsNot Nothing AndAlso Not t.IsCompleted).Count + Dim finished$ = threads.Where(Function(t) t IsNot Nothing AndAlso t.IsCompleted).Count + + Return $"[free: {free}, running: {running}, finished: {finished}]" + End Function + Public Iterator Function RunParallel() As IEnumerable(Of TOut) Do While taskList.Count > 0 Dim i As Integer = GetEmptyThread() If i > -1 Then threads(i) = New AsyncHandle(Of TOut)(taskList.Dequeue).Run + Call Console.WriteLine($"{ToString()} submit new task on thread [{i + 1}]!") End If Dim j As Integer = GetCompleteThread() @@ -47,6 +56,7 @@ Public Class ThreadTask(Of TOut) If j > -1 Then Yield threads(j).GetValue threads(j) = Nothing + Call Console.WriteLine($"{ToString()} [thread_{j + 1}] job done!") End If Loop @@ -56,6 +66,7 @@ Public Class ThreadTask(Of TOut) If j > -1 Then Yield threads(j).GetValue threads(j) = Nothing + Call Console.WriteLine($"{ToString()} [thread_{j + 1}] job done!") End If Loop End Function