I am reading a blog post on the code quality of the Doom 3 source code, and I’ve gotten stuck on a piece of C++ code I can not make sense of. I should say that I am not a C++ programmer.
The offending code looks as follows:
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).
}
}
(taken from http://fabiensanglard.net/doom3/index.php, under the topic “Unrolling the loop”)
This looks to me as a closure being passed as a parameter to the return value of Sys_StartAsyncThread() – but to my knowledge this is not possible in C++, and also Sys_StartAsyncThread() is of void type, so what’s going on here?
The definition of Sys_StartAsyncThread() can be found here.
It looks like a typo. According to here, there should be a semicolon after
Sys_StartAsyncThread();.