【发布时间】:2012-03-08 12:44:10
【问题描述】:
如何在 D 中使用 core.thread 正确传递句柄?我试过这样做,但是手柄会改变,我不知道为什么:
void WorkerThread(handle hand)
{
…
}
…
auto worker = new Thread( { WorkerThread( m_handle ); } );
【问题讨论】:
如何在 D 中使用 core.thread 正确传递句柄?我试过这样做,但是手柄会改变,我不知道为什么:
void WorkerThread(handle hand)
{
…
}
…
auto worker = new Thread( { WorkerThread( m_handle ); } );
【问题讨论】:
Thread 构造函数可以接受一个可以具有上下文的委托。在显示的代码中,上下文是封闭函数。如果由于某种原因这是一个问题,您应该能够执行以下操作:
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 );
}
【讨论】: