• Advertisement
Sign in to follow this  

Multithreaded programming

This topic is 1884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking to make a little game project of mine and could use some advices.

 

I'll be using C++ and i'm aware of both SFML and SDL. Are there any other good 2D libraries out there for C++ that I should know of? Secondly, I wanna learn more about multithreaded programming so I want to make a game that would force me to use this.

 

Any advices on a game project  and what 2D library to use would be appreciated. 

Edited by Johnell

Share this post


Link to post
Share on other sites
Advertisement

If you want to learn about multithreading, why not do a project just to test and learn the MT stuff, outside of a game?  Trying to learn MT while at the same time doing everything you need for a game is really hard, and will mostly lead to frustration and pain when you're starting out.  Some of the worst bugs to track down and fix are MT bugs.  So, I'd recommend finding some project that you can do as a simple console application that is highly parallelizable, and learn the basics of MT from there.

 

Learn and practice one thing at a time.  When you're competent enough with how MT works, then you can start to think how you can apply it to a game engine.

Share this post


Link to post
Share on other sites

If you wan't to learn MT, go for simple app, like FTP Client-Server. Write it with C for the fun of it.

 

It'l teach you one thing i learned - Don't resort to MT.... like ever... unless really needed.

Edited by Sollum

Share this post


Link to post
Share on other sites

Most engines will hide MT from you, they let you execute your methods/functions every n frames or every n seconds.

If you are looking for a good 2D one that is C/C++, I really like orx, since it allows you to change things in your game really fast and supports nearly everything you need (such as physics and particles). The only drawback is that it has no network support, also, you won't be able to use threads on this one (but as I said, every engine I know will hide MT from you).

 

If you are really into learning MT, go for the classic problems, such as the dining phylosophers:

http://en.wikipedia.org/wiki/Dining_philosophers_problem

Share this post


Link to post
Share on other sites

If you want top-quality reading material with C++ (specifically C++11 and its standard threading library) and threading in mind, I can recommend C++ Concurrency in Action: Practical Multithreading by Anthony Williams (http://www.amazon.co.uk/dp/1933988770) and Herb Sutter's many articles (http://herbsutter.com/).

 

Pre-C++11 you can use boost::thread (nearly identical to std::thread in C++0x/C++11), so any articles concerning std::thread can also be applied to earlier versions of C++ supported by boost.

Share this post


Link to post
Share on other sites

alnite, on 25 Feb 2013 - 15:21, said:
As people have said, multithreading needs to be threaded carefully (pun intended).

If you truly want to learn it, here's a fun thing you can do: make an audio player. With SDL/SFML or whatever GUI lib you decide to use, create a Load, Play, Pause, Stop buttons. Then there should be an audio playing in the background. Try playing a really big audio file (100MB WAVs), without loading it all up at once. Playing audio must be done on a separate thread. Load/Play/Pause/Stop buttons must be able to signal that thread appropriately, and the audio thread must signal back to the main thread.

That's actually what I was going to suggest. +1

Before you get into that bundle of fun, though, you should probably just sit down and play with making small threaded programs that don't do much of anything, like looping counters and the like. Understand what mutexes and critical sections and such do and how to use them. Understand how to terminate a thread from within itself or from another thread. Get familiar with the functionality of your chosen thread-lib basically.

Share this post


Link to post
Share on other sites

What kind of projects would allow me to focus on multithreading, while still building something?

I wrote a multithreaded software raycaster one time and it was really fun, I then ported it to the GPU. I find some things work naturally for MT, the two situations I find it particularly useful in is either when you need to do the same thing over and over again on different data (eg. my raycaster) or when you need to do two tasks that have almost nothing to do with each other.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement