Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
c++11 multithreading?
I'm finding it hard to find an example of code using c++11 threads where the use of more threads on a multi-core machine is beneficial? Can anyone point me in the right direction?
1 Answer
- BrianLv 56 years ago
Threading is normally handled by the operating system. As such to create a thread in c++ you have to call a system call. This system call is different in Unix or Windows. pthreads is what my school thought for multithreading, however my school also mostly wanted people to use Unix. Since I now work mostly with vb.net or C#.net I can't tell you of the top of my head what the windows system call is.
The reason you want to use multithreading is so that you can do multiple things at once. For example if on a browser you have multiple tabs open at once normally each tab will get its own thread. This way if one thread runs into problems you only have to close one tab instead of the whole browser. A basic example of multithreads is on servers... each site request spins of its own thread and then the server can wait for the next site request. In games you can run the background music in one thread while you run the boss ai on another, the player graphics on another thread and so on and on and on.
I'm not sure how much you know or want to know about threading, but basically every operating system is constantly running multiple threads all the time. In most programs you won't need it as you want to program linear programs, however it can be useful if you need to run something in the background...
If you do use multithreading please make sure you are aware of how to make your program thread safe so that you don't have two threads trying access and change the same object at the same time...