DOTS: Race conditions and NativeContainers?

I have an entity Unit and an entity Task. I am finding the closest task to a unit. I do this by passing in all the tasks into the job and iterate over them and calculate the closest. This works but the problem is that the same task can be assigned to two different units, which should not be allowed. This is because I cannot think of a safe way for updating my taskDataArray without creating race conditions.

  [BurstCompile]
  struct FindTaskForUnit : IJobForEachWithEntity<Unit, Translation>
  {
    public EntityCommandBuffer.Concurrent commandBuffer;
    [DeallocateOnJobCompletion] [ReadOnly] public NativeArray<TaskData> taskDataArray;

    public void Execute(Entity entity, int index, ref Unit c0, [ReadOnly] ref Translation c1)
    {
      float3 unitPosition = c1.Value;
      Entity closestTask = Entity.Null;
      float closestTaskPosition = 0f;

      for (int i = 0; i < taskDataArray.Length; i++)
      {
        // Calculate closest task
      }

      if (closestTask != Entity.Null)
      {
        commandBuffer.AddComponent(0, entity, new HasTask { Task = closestTask });
      }
    }
  }

Removing the [ReadOnly] from the taskDataArray and using it to save changes doesn’t help because writing and reading to the same array is not allowed. Adding [NativeDisableContainerSafetyRestriction] to circumvent this will cause race conditions. The CommandBuffer will be executed after the job is finished so it will not help.

Is there a NativeContainer type which allows both safe writing and reading in the same job? If not, I guess the only solution is to do the duplicate check on the main thread?

These links will direct you to similar problems that have been discussed with considerable depth: