My stream is:
NativeStream stream = new NativeStream(SystemInfo.ProcessorCount, Allocator.TempJob)
So it has as many buffers as the number of threads, so I can write on each buffer depending on which thread I am when I'm on a huge IJobParallelFor, which is apparently safe.
I just want to be able to concurrently append all the values I generate, but with the safety of writing only from one thread to one buffer.
I pass the NativeStream to a job with AsWriter() . Then I call BeginForEachIndex(threadIndex), then stream.Write(value) and then EndForEachIndex() .
Well, seems like the ThreadIndex must be 0 only now. I get an ArgumentException: Index X is out of restricted IJobParallelFor range [0..0]
I saw that when you create a Writer, it resets the internal counters! But to the MinValue... I wonder what I'm doing wrong.
` internal Writer(ref NativeStream stream)
{
m_Writer = stream.m_Stream.AsWriter();
#if ENABLE_UNITY_COLLECTIONS_CHECKS
m_Safety = stream.m_Safety;
CollectionHelper.SetStaticSafetyId(ref m_Safety, ref s_staticSafetyId.Data, "Unity.Collections.NativeStream.Writer");
m_Length = int.MaxValue;
m_MinIndex = int.MinValue; <----------------
m_MaxIndex = int.MinValue; <-------------------
#endif
#if ENABLE_UNITY_COLLECTIONS_CHECKS || UNITY_DOTS_DEBUG
m_PassByRefCheck = null;
#endif
}`