Put thread pool to individual type define as thread resource manager.

This commit is contained in:
Youmu Liu
2025-10-22 20:35:05 +08:00
parent 3788db4cd0
commit 3707e5bd74
4 changed files with 93 additions and 20 deletions
@@ -45,6 +45,7 @@ namespace StgSharp.Mathematics.Numeric
{
ID = id;
_threads = new Thread[wrapSize];
_resetHandle = new Handle[wrapSize];
for (int i = 0; i < wrapSize; i++)
{
_threads[i] = new Thread(MatrixParallelWorker)
@@ -53,7 +54,23 @@ namespace StgSharp.Mathematics.Numeric
Priority = ThreadPriority.BelowNormal,
Name = $"MPT#{ID}_{i}"
};
_threads[i].Start(new Handle(i, this));
Handle handle = new Handle(i, this);
_resetHandle[i] = handle;
_threads[i].Start(handle);
}
}
public bool IsAllAvailable
{
get
{
foreach (Handle item in _resetHandle)
{
if (item.Role != 0) {
return false;
}
}
return true;
}
}
@@ -75,6 +92,21 @@ namespace StgSharp.Mathematics.Numeric
}
}
internal bool TryGetLeaderHandle(out Handle? handle)
{
foreach (Handle item in _resetHandle)
{
if (item.Role != 2)
{
handle = item;
item.Role = 2;
return true;
}
}
handle = null;
return false;
}
public class Handle(int inWrapIndex, MatrixParallelWrap wrap)
{