codeguru
3rd November 2007, 13:36
Hi folks,
I modified a vdub filter to support up to 16 CPUs, using the CreateThread() function.
Now my question - is it better to create threads dynamically (e.g. 4 threads per filtered picture) which will calc immediately (and exit) after being created or having threads created once with the flag CREATE_SUSPEND (parameter 5) in the background? A repeated call of CreateThread() should be cached, and the second way will need to implement somme callbacks for message handling, that will eat up the performance gain of creating threads only once in a filter usage.
There are no information about the latencies due to the system message passing, and the timertick is too short for precise measurements in microseconds.
At least a Q6600 has enough cache to hold 1 kb of code so my choice was this:
void dodnrMMX_schedule(Pixel32 *dst, Pixel32 *src, PixDim w, PixDim h, PixOffset modulo, __int64 thresh1, __int64 thresh2, void *p, unsigned long nT)
{
dnrparams_t dnrp[MAXTHREADS];
HANDLE threadHandles[MAXTHREADS];
int n;
int delta;
void *pparams;
for(n=0;n<nT;n++)
{
....
some code for dividing src and dst in smaller pieces
...
threadHandles[n]=CreateThread(
NULL,
0,
dodnrMT,
&dnrp[n],
0,
&dnrp[n].threadid);
}
WaitForMultipleObjects(
nT,
threadHandles,
TRUE,
INFINITE);
}
I modified a vdub filter to support up to 16 CPUs, using the CreateThread() function.
Now my question - is it better to create threads dynamically (e.g. 4 threads per filtered picture) which will calc immediately (and exit) after being created or having threads created once with the flag CREATE_SUSPEND (parameter 5) in the background? A repeated call of CreateThread() should be cached, and the second way will need to implement somme callbacks for message handling, that will eat up the performance gain of creating threads only once in a filter usage.
There are no information about the latencies due to the system message passing, and the timertick is too short for precise measurements in microseconds.
At least a Q6600 has enough cache to hold 1 kb of code so my choice was this:
void dodnrMMX_schedule(Pixel32 *dst, Pixel32 *src, PixDim w, PixDim h, PixOffset modulo, __int64 thresh1, __int64 thresh2, void *p, unsigned long nT)
{
dnrparams_t dnrp[MAXTHREADS];
HANDLE threadHandles[MAXTHREADS];
int n;
int delta;
void *pparams;
for(n=0;n<nT;n++)
{
....
some code for dividing src and dst in smaller pieces
...
threadHandles[n]=CreateThread(
NULL,
0,
dodnrMT,
&dnrp[n],
0,
&dnrp[n].threadid);
}
WaitForMultipleObjects(
nT,
threadHandles,
TRUE,
INFINITE);
}