Search Unity

Feature Request Globally accessible thread index

Discussion in 'C# Job System' started by half_voxel, Jan 9, 2023.

  1. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    This is more of a feature request because I don't think this is available right now.

    But please, Unity devs, it would be amazing to be able to access the current thread's index without having to use NativeSetThreadIndex. It is such a pain to have to pass the thread index along everywhere, sometimes requiring large refactoring. This is especially annoying for debugging tools which write to some buffers, but need to be able to write to different streams depending on the thread index to avoid races. Debugging tools are used in various places in the code, and it's a pain to have to refactor code a lot just to be able to pass the thread index.

    Even having burst-accessible local thread storage would be enough, but we don't get that either right now.

    I know this is possible. Because Unity allows using Debug.DrawLine from burst code, and that must be using the local thread index at some point to avoid data races (unless it's locking, but I highly doubt that from a performance perspective).

    Is this on the roadmap at some point?