d语言线程

d语言线程,d,dmd,D,Dmd,如何在D中使用core.thread正确传递句柄?我尝试过这样做,但手柄会改变,我不知道为什么: void WorkerThread(handle hand) { … } … auto worker = new Thread( { WorkerThread( m_handle ); } ); 线程构造函数可以接受具有上下文的委托。在所示代码中,上下文是封闭函数。如果出于某种原因出现问题,您应该能够执行以下操作: void StartThread(handle hand) {

如何在D中使用
core.thread
正确传递句柄?我尝试过这样做,但手柄会改变,我不知道为什么:

void WorkerThread(handle hand) 
{
    …
}

…

auto worker = new Thread( { WorkerThread( m_handle ); } );

线程
构造函数可以接受具有上下文的委托。在所示代码中,上下文是封闭函数。如果出于某种原因出现问题,您应该能够执行以下操作:

void StartThread(handle hand) {
  struct Con {
    handle m_handle;
    void Go() { WorkerThread( m_handle ); }
  }

  Con con = new Con;
  con.m_handle = hand;
  auto worker = new Thread( &con.Go );
}

线程
构造函数可以接受具有上下文的委托。在所示代码中,上下文是封闭函数。如果出于某种原因出现问题,您应该能够执行以下操作:

void StartThread(handle hand) {
  struct Con {
    handle m_handle;
    void Go() { WorkerThread( m_handle ); }
  }

  Con con = new Con;
  con.m_handle = hand;
  auto worker = new Thread( &con.Go );
}