It has the benefit of being multi platform so you can write code once and compiler it anywhere, also you don't need to investigate a series of cryptic Win API methods. Additionally, since it's C++, it's a much more streamlined, object oriented approach to doing threading which will result in more readable and shorter code.
[ J ] a [ Y ]
2010-08-17 03:50:54 UTC
On Windows:
*Include windows.h
*Find some decent win32 API doco; I reccomend using API Guide.
*The API you're looking for is called CreateThread(...)
juliepelletier
2010-08-17 03:40:10 UTC
Multi-threading requires a good technical analysis to be efficient, but if you're a good programmer, you should be able to get it done.
The functions to use depend on your environment (compiler, OS).
A simpler approach is often possible in batch processing. Sometimes you could simply find a way to split the task and run a few processes simultaneously. This method often performs better, if applicable. The same principle could be done in a single program using fork().
ItachisXeyes
2010-08-17 03:34:30 UTC
its beyond my ability to fully explain how to do that here. however i can point you in the right direction;
look into multi-threading and parallel programming.
just a warning, it will make your code slightly more confusing, XD
but well worth the trade off.
Cubbi
2010-08-17 04:08:01 UTC
I'd say you have three basic directions you can take this:
1) redesign the program for multithreading and use std::threads (if already supported by your compiler) or boost.threads (if not): http://www.boost.org/doc/libs/1_44_0/doc/html/thread/thread_management.html
2) make use of std::packaged_task / boost::packaged_task ( http://www2.research.att.com/~bs/C++0xFAQ.html#std-future and http://www.boost.org/doc/libs/1_44_0/doc/html/thread/synchronization.html#thread.synchronization.futures.reference.packaged_task )
3) get serious and use MPI, for which boost.MPI is the most C++-friendly approach: http://www.boost.org/doc/libs/1_44_0/doc/html/mpi/tutorial.html
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.