Epic Games fired me so I wrote my own multi-threaded game engine called RealEngine. Here’s a snippet.
Thread 1:
loadAssets();
launchUI();
realEngineStarted = true;
cache_t * c = objCacheInit();
…
Thread 2:
while (!realEngineStarted) { }
objCacheInsert(c, new Sprite(“mario”));
…
Is my code buggy? Explain why or why not. If there is a bug, explain how we might fix it.
Thread 1 is coded correctly as the functions are geting invoked and there is no initial condition but as we know the threads work in relation to each other, if the assets are loaded and the game is launched we expect the cache files to come into play and store the data as we move further with the execution BUT in thread 2, the condition is given that while realEngine is NOT started, the cache object should be generated which is incorrect. Hence the correct code should be like:
Thread 1:
loadAssets();
launchUI();
realEngineStarted = true;
cache_t * c = objCacheInit();
…
Thread 2:
while (realEngineStarted) { }
objCacheInsert(c, new Sprite(“mario”));
Get Answers For Free
Most questions answered within 1 hours.