Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何core.thread在 D 中正确传递句柄?我试过这样做,但是手柄会改变,我不知道为什么:
core.thread
void WorkerThread(handle hand) { … } … auto worker = new Thread( { WorkerThread( m_handle ); } );
构造Thread函数可以接受一个可以有上下文的委托。在显示的代码中,上下文是封闭函数。如果由于某种原因这是一个问题,您应该能够执行以下操作:
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 ); }