mirror of
https://github.com/DCFApixels/DragonECS-ClassicThreads.git
synced 2025-09-17 19:24:37 +08:00
update multi-exception in threads
This commit is contained in:
parent
10bad36486
commit
9d7e2b9003
@ -11,10 +11,12 @@ namespace DCFApixels.DragonECS
|
|||||||
private static ThreadWorkerHandler _worker;
|
private static ThreadWorkerHandler _worker;
|
||||||
private static ThreadWorkerHandler _nullWorker = delegate { };
|
private static ThreadWorkerHandler _nullWorker = delegate { };
|
||||||
private static int[] _entities = new int[64];
|
private static int[] _entities = new int[64];
|
||||||
|
private static List<Exception> _catchedExceptions;
|
||||||
|
|
||||||
private static void ThreadProc(object obj)
|
private static void ThreadProc(object obj)
|
||||||
{
|
{
|
||||||
ref ThreadReacord record = ref _threads[(int)obj];
|
int i = (int)obj;
|
||||||
|
ref ThreadReacord record = ref _threads[i];
|
||||||
|
|
||||||
while (Thread.CurrentThread.IsAlive)
|
while (Thread.CurrentThread.IsAlive)
|
||||||
{
|
{
|
||||||
@ -25,10 +27,12 @@ namespace DCFApixels.DragonECS
|
|||||||
_worker.Invoke(new ReadOnlySpan<int>(_entities, record.start, record.size));
|
_worker.Invoke(new ReadOnlySpan<int>(_entities, record.start, record.size));
|
||||||
record.doneWork.Set();
|
record.doneWork.Set();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
if (_catchedExceptions == null)
|
||||||
|
_catchedExceptions = new List<Exception>();
|
||||||
|
_catchedExceptions.Add(e);
|
||||||
record.doneWork.Set();
|
record.doneWork.Set();
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,6 +97,12 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
_worker = _nullWorker;
|
_worker = _nullWorker;
|
||||||
|
if(_catchedExceptions != null)
|
||||||
|
{
|
||||||
|
var exceptions = _catchedExceptions;
|
||||||
|
_catchedExceptions = null;
|
||||||
|
throw new AggregateException("Mutiplie exceptions", exceptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct ThreadReacord
|
private struct ThreadReacord
|
||||||
@ -100,7 +110,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public Thread thread;
|
public Thread thread;
|
||||||
public ManualResetEvent runWork;
|
public ManualResetEvent runWork;
|
||||||
public ManualResetEvent doneWork;
|
public ManualResetEvent doneWork;
|
||||||
|
|
||||||
public int start;
|
public int start;
|
||||||
public int size;
|
public int size;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user