Put thread pool to individual type define as thread resource manager.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user