Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda