Question

Epic Games fired me so I wrote my own multi-threaded game engine called RealEngine. Here’s a...

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.

Homework Answers

Answer #1

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”));
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT