Sign in to follow this  
texel3d

Multi-threading libraries

Recommended Posts

texel3d    156
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.

Share this post


Link to post
Share on other sites
Antheus    2409
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.

Share this post


Link to post
Share on other sites
the_edd    2109
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.

Share this post


Link to post
Share on other sites
Lode    1003
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?

Share this post


Link to post
Share on other sites
texel3d    156
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 ?

Share this post


Link to post
Share on other sites
the_edd    2109
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this