Jump to content
  • Advertisement
Sign in to follow this  
EmpireProductions

MultiThreading

This topic is 3055 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 have a question about making a application Multithreaded. What is NEEDED to make a app. multithreaded? I have this: boost::thread netupdate(boost::bind(&WorldNetTranslator::update, netTranslator)); netupdate.join(); Is that all that is needed or is there more that I am missing?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by EmpireProductions
I have a question about making a application Multithreaded. What is NEEDED to make a app. multithreaded?

I have this:

boost::thread netupdate(boost::bind(&WorldNetTranslator::update, netTranslator));
netupdate.join();

Is that all that is needed or is there more that I am missing?


That is all you need to run netTranslator.update() in another thread yes. There's of course a lot more to multithreading in general, but if that's all you need then there's nothing else to it.

Share this post


Link to post
Share on other sites
Ok thanks. Is there any special ways you should program your classes and methods you want run in other threads and if so what should I be taking into consideration and doing in order to get the best results?

Share this post


Link to post
Share on other sites
Quote:
Original post by EmpireProductions
Ok thanks. Is there any special ways you should program your classes and methods you want run in other threads and if so what should I be taking into consideration and doing in order to get the best results?


Yes :)

Learn about the different uses for concurrency (throughput vs responsiveness) and which idioms are used for each. Think in terms of tasks rather than threads. Use various kinds of queues, pools and parallel patterns to perform those tasks. Reduce shared state.

Read all of this. I found this to be quite good, too.

If you're more interested in getting stuff done and don't really care to know what's going on under the hood, then I suggest using established frameworks such as Intel's Threaded Building Blocks.

Share this post


Link to post
Share on other sites
Quote:
Original post by EmpireProductions
Is there any special ways you should program your classes and methods you want run in other threads and if so what should I be taking into consideration and doing in order to get the best results?
It requires a slightly different way of thinking.

The code does not follow one single thing at a time, but it is instead at any number of places at the same time. When debugging you aren't at a single location, but at one location in every thread. You might be in two, or five, or a hundred different places at once.

The added dimension of being in multiple places at once introduces an extra dimension of bugs such as race conditions and deadlock behaviors.

It is not difficult or labor intensive to code correctly, but it certainly takes some effort.


The world of parallel processing has many algorithms and patterns available.

The most simple and trivial example is distribution of work through tasks and transactions. This is a worker pool with tasks spread out to the first available processor. It is easy to implement and therefore one of the most common and popular algorithms.

That pattern doesn't offer much in terms of algorithmic benefit. It doesn't offer much benefit in terms of optimization. It causes slowdowns when processing is not your bottleneck. It can mean unnecessary data dependencies and locking. ... But it is the first (and frequently only) pattern that many people use, and it is important to learn.


More efficient applications of parallel processing require more intellectual work, and are therefore shunned. [grin] The steps are basically to subdivide the work into the component tasks, determine the dependencies and communications needs, group them to minimize those costs, and then map them to the appropriate processes. Then you implement it. The results can be substantially better than simply running serial algorithms in a master/worker pattern.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!