Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
What does the non-uniqueness of the Task.Id property mean?

On docs.microsoft.com says:

Note that although collisions are very rare, task identifiers are not guaranteed to be unique.

Does this mean that there can be tasks with the same IDs in the heap at the same time? Or does it mean that it can't be, but there are tasks with IDs that other tasks already had that no longer exist?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It means that if you create 4,294,967,295 tasks, and read the Id property of each one of them, the first and the last task will both have the value 1 as Id.

You can see the source code of the Task.Id property here. Below is the essence of this code:

public class Task
{
    private volatile int m_taskId;

    public int Id
    {
        get
        {
            if (m_taskId == 0)
            {
                int newId = NewId();
                Interlocked.CompareExchange(ref m_taskId, newId, 0);
            }
            return m_taskId;
        }
    }

    internal static int s_taskIdCounter;

    internal static int NewId()
    {
        int newId = 0;
        do
        {
            newId = Interlocked.Increment(ref s_taskIdCounter);
        }
        while (newId == 0);
        return newId;
    }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda