0
\$\begingroup\$

Ok so I want to know what is a proper way to create a multi threaded game. What I have tried is implement a wait and notify between the game logic thread and the drawing thread, but I believe this is a very bad way to do it because one thread waits for the other to finish what it is doing before it can continue to do it`s own task. I mean, I think this kind of beats the whole point. So a better way I am thinking of would be to have blocking queues(I would need more than one for all the different types of data in my game) and the updating thread would put all of the updated/processed values into it and if it was full, the updating thread would block. The drawing thread would then read all of those values and if the queues were empty it would block. This way both the threads are fully utilized. But I don't know if this would be the professional or good way to do it, which is why I am posting this so I can get a little guidance. Thanks!

\$\endgroup\$
  • \$\begingroup\$ Is your question not answered here? How many threads should an Android game use? \$\endgroup\$ – MichaelHouse Aug 30 '14 at 3:09
  • \$\begingroup\$ Kind of.. but I am not using openGL. I'm using a surface view to which I am drawing to with a canvas. And also it doesn't describe how it is actually done, but rather the number of threads to have.. Doesn't talk about blocking queues or any of what is in my question. \$\endgroup\$ – user3843164 Aug 30 '14 at 3:35
  • \$\begingroup\$ Half a year ago I had similar problem - however I solved it by returning to single-threaded version. Why? The single-threaded performance was acceptable and it just was not worth the effort for performance I did not need. (not mentioning random crashes as you must sync everything manually, java wont help here much) \$\endgroup\$ – wondra Aug 30 '14 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.