Multi-threading libraries

Started by
6 comments, last by the_edd 16 years, 4 months ago
Hi, i need to use threads in my real-time 3d application (Direct3D). I havn't any experience with thread programming. I don't know which library to use. Which library is "the best" for 3d applications ? pthread ? OpenMP ? other ? Thanks.
Advertisement
use functions like: _beginthreadex,
that are already in <process.h>.
You could always use boost threads.
Quote:Which library is "the best" for 3d applications ?


Until utopia becomes reality, there will always be "optimal" and "compromise".

Since you mention DX, using windows threads will probably be the most straightforward choice.

OpenMP is intended for different things than threading. For certain types of concurrency it's the natural choice. If you find yourself with types of tasks that OpenMP was designed to solve, then it would be optimal choice.

pthreads and boost threads are probably overkill here, unless you want portability between platforms.

But above all, threads aren't something you apply liberally to a project. Especially for computationally intensive tasks, the number of threads will often be limited to one per physical processor, to avoid the overhead.
For general purpose threading, I'd go with boost threads. They're being adopted in to the next C++ standard (with a handful of small changes) so you'll be future proofing yourself somewhat by learning them.

OpenMP is best for loop-based parallelism. It can be used for other stuff too but it gets a little trickier (version 3 of the spec has made inroads in to more general parallelism, I hear). For example, OpenMP would be a great tool to use for basic ray-tracing, fractal rendering or any other "embarrassingly parallel" algorithm. The other thing about OpenMP is that it is not available everywhere, though it is available in newer versions of MSVC (>= v8) and GCC (>= 4.2), which realistically will get you pretty far.

Intel's threading building blocks made a bit of a stir a few months back (probably because it was open sourced more than anything else), but you could also look at that. I haven't had time to, yet.
SDL provides threads too, but since you're using Direct3D there is probably no point in using SDL for your project.

OpenMP in visual studio appearantly forces to have to provide redistributables with your project that must work with manifests, not really nice for the installer. Does anyone know a way to do it without?
I will use multi-threading for Virtual texture and maybe physics (later).
Does boost has some interesting things that Windows threads do not have ?
Or is it just a base for a future standard ?
Quote:Original post by texel3d
I will use multi-threading for Virtual texture and maybe physics (later).
Does boost has some interesting things that Windows threads do not have ?


Condition variables is the big one. I think most would agree that programming using condition variables as popularised by pthreads, is much less error prone than event variables as found in the windows API.

scoped locks are another incredibly important addition that help with correctness in the face of exceptions. Since the Win32 api is not C++, it cannot provide such a facility that inherently depends on destructors). Boost also has a thread_group class, which is some what easier to use than WaitForMultipleObjects.

By employing boost bind and boost function, it is also easy to call an arbitrary function in another thread. This is generally much more tedious with C-level APIs such as pthreads and Win32. I took this another stage further in my async library, based on boost threads.

There's also a very flexible thread pool implementation built on top of boost threads at http://threadpool.sourceforge.net/.

And of course, by using thr boost stuff and a little care you get portability for free, which may or may not matter to you.

This topic is closed to new replies.

Advertisement