c# - thread.join是否同时启动所有线程

标签 c# multithreading

    Thread[] threads = new Thread[12];
    int temp;

    //_stopRequest = false;
    for (int i = 0; i < threads.Length - 1; i++)
    {
        temp = i;
        threads[temp] = new Thread(new ThreadStart(() => test(test1[temp],"start", temp)));
        threads[temp].Start();
        //threads[temp].Join();
    }

   for(int i=0; i<threads.Length-1; i++)
   {
     threads[i].Join();
   }

谁能帮我解释一下吗

最佳答案

不,线程在您调用 Start() 时启动。

如果您在 Start()(注释掉的代码)之后立即调用 Join(),则每个线程都将启动,然后当前线程的执行将停止,直到第一个线程停止。所以它实际上充当了单个线程。

现在的代码是这样的,所有线程都启动,然后当前线程等待所有启动的线程完成。

关于c# - thread.join是否同时启动所有线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32673670/

相关文章:

java - 当 A Thread(list.add()) 和 B Thread(list.size()) 工作时,这条线如何工作?

android - 第二次运行后我收到消息 "Only the original thread that created a view hierarchy can touch its views."

c# - ASP.NET C# 线程中止异常?

c++ - 设计问题:std::map 的线程安全

c# - 查询子属性时同时选择父项和子项

c# - 如何使用 Net Topology Suite 在 Entity Framework Core 中缓冲一个点(地理)1 米

c# - 将字符串列表投影到 SQL 语句列表

c# - 将 double 值乘以 100.0 会引入舍入误差?

c# - 代码首次尝试创建数据库时出现异常

c# - ManualResetEventSlim 建议的等待时间