Is Task.Factory.StartNew() guaranteed to create at least one new thread?

前端 未结 6 1997
一生所求
一生所求 2021-01-24 14:38

I understand that the TPL does not necessarily create a new thread for every task in a parallel set, but does it always create at least one? eg:

private void MyF         


        
6条回答
  •  既然无缘
    2021-01-24 15:40

    Your main question and the question in your code are completely different questions. But the answers to the two questions are:

    1) No, there's no guarantee a thread will be started. What is created and started is a task. Ultimately, some thread will have to execute that task, but whether one will be created is unspecified. An existing thread could be re-used.

    2) It depends what you mean by "immediately". Strictly speaking, there is no timeliness guarantee. But you have told the system to execute that task, and it will at least start it as soon as it finishes everything it considers more important. Strict fairness or timeliness is not guaranteed.

提交回复
热议问题