A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'Data Oriented Technology Stack' started by Antypodish, Nov 13, 2018.
Is there a way of getting thread ID on running job?
Ah nice, that was simpler than I thought
I just link it here for reference
[Unity.Collections.LowLevel.Unsafe.NativeSetThreadIndex] public int threadIndex;
Out of interest what is your use case for this ?
So I am working on modding tool for my project. Something like interpreted language (i.e. lua), where I can run custom methods and scripts to drive my game, but using ECS and multithreading. All data is compiled into int(s) NativeArrays. At this point, I don't want use ECS precompiled dlls. But anyway.
So my data as I said is stored in NativeArrays.
So lets say I got 100k instances, or entities as in following benchmark example.
Each entity runs custom script sample. In this case Health regeneration mock-up.
Each entity hold own persistent information, for example health.
But custom methods sequence executed by each entity, is accessed from same NativeArray, which holds only temporary data, for given entity execution.
However, I can not write to the same method variable (data index in native array) from different entities, while multithreading, to avoid race conditions.
Hence, I multiply required methods data by number of possible threads. This way resizing my NativeArray to required size.
So imagine that my method of regenerating health for example, requires 10 reserved indexes in NativeArray, to store temporary data. If I got 8 thread, that I need multiply by 8. Hence I need 80 size of NativeArray.
Now every entity run on thread, gets information about current thread ID.
This way, I got offset to right set of data in NativeArray.
Hence in this case, I got only 8 duplicates of regenartion methods, rather than 100k duplicates of regeneration methods.
And now I can scale it nicely.
But work in progress.
Does that makes any sense?