我正在阅读关于Doom 3源代码的代码质量的博客文章,我已经陷入了一段我无法理解的C++代码.我应该说我不是C++程序员.
违规代码如下:
Sys_StartAsyncThread(){ // The next look runs is a separate thread.
while ( 1 ){
usleep( 16666 ); // Run at 60Hz
common->Async(); // Do the job
Sys_TriggerEvent( TRIGGER_EVENT_ONE ); // Unlock other thread waiting for inputs
pthread_testcancel(); // Check if we have been cancelled by the main thread (on shutdown).
}
}
Run Code Online (Sandbox Code Playgroud)
(摘自http://fabiensanglard.net/doom3/index.php,主题为"展开循环")
这看起来像一个闭包被作为参数传递给返回值Sys_StartAsyncThread()- 但据我所知,这在C++中是不可能的,而且也是Sys_StartAsyncThread()void类型,所以这里发生了什么?
定义Sys_StartAsyncThread()可以在这里找到.