last day (56 days later) » 

10:13 PM
ok
3
 
So what threading APIs do you guys prefer to use? Specifically for thread pooling. I'm working on a project in which I need to have a thread pool, but am not sure of the most efficient way to pool my threads.
Basically I have a queue of operations that I need to distribute across multiple threads. I'm working on an image recognition engine.
 
@IDWMaster boost::threadpool
 
@TonyTheLion I've considered that, but unfortunately boost won't work on Visual Studio 11, which is required for the project I'm working on.
 
@IDWMaster: openmp (3.0) is the only thing I've found remotely usable except for intl TBB (which is a bit pricey)
@IDWMaster: boost doesn't work for VS11?
 
sbi
Yawn.
3
 
10:24 PM
@Grizzly Yeah, it doesn't compile under the VS command prompt
Boost build doesn't work
I'll probably end up implementing my own thread pool, but what are some general guidelines for doing so? I need to figure out a way to dynamically change the number of running threads depending on the amount of work.
But also avoid constantly creating and destroying threads
Our client needs this to compile under VS 11 and GCC
Under VS 11 it will be compiled for Windows 8, and under GCC it will be compiled for Linux, Windows, and embedded systems.
 
@IDWMaster: Why would you dynamically change the number of threads? But good luck with writing your own threadpool, you'll certainly need it
 
@Grizzly It would be something similar to the way .NET does thread pools
The reason it has to be dynamically changed is because the workload varies
I could have a million requests coming in at once, or only 10.
 
@IDWMaster: so? you only have a limited number of cores
 
@Grizzly OSs don't usually give a 1:1 mapping of virtual threads to physical cores though. I know that in my .NET experience it was suggested to use more threads than physical cores.
Especially when threads would block
 
Then use more threads then cores, no reason to change the number on the fly though
 
10:40 PM
@Grizzly Why does the MS implementation of thead pools do this in .NET? They must have had a reason.
 
@IDWMaster: Do you have any references for that? I'd be suprised if it really did
Doesn't make sense to do so
 
"Sets the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction." - msdn.microsoft.com/en-us/library/y5htx827.aspx
There's also a SetMaxThreads function
 
Ok that's kind of pointless
it's not like they couldn't just create the max number of threads and let all unused sleep
 
I think the idea is that the more threads in use the more memory is in use
 
Not really a concern
 
10:50 PM
Hmm. They must have some good reason for doing it.
 
unless you are really strapped for memory
 
On an embedded system that may be the case
 
I'm still not convinced they do that (for desktop at least)
 
It does actually do that
I've written enough .NET programs to know it works that way
 
The interface might simply be designed to do that
 
10:51 PM
Even on the desktop
 
Ok, then I don't know (nor care)
you still don't want to do that, since you have more important problems when wirting your own threadpool
nanmely low overhead scheduling of your tasks
 
Right now I'm writing it so it stores it in Array and uses mutex handles for threads to wait on (i.e. CreateMutex)
 
As I said you have bigger problems
 
11:33 PM
Is this room for real? I don't see a single C++ code snippet!
template<typename T, typename U>
auto add(const T& t, const U& u) -> decltype(t + u)
{
    return t + u;
}
 
@FredOverflow Well there you have one!
And yes; this room is real.
Interesting use of auto by the way.
 
11:50 PM
@FredOverflow: Not for long I would expect
@IDWMaster: Why interestin, seems to be a pretty standard example for the new function declaration syntex to me
 

  last day (56 days later) »