GThreads and GThreadPool help for a dummy


I'm not really experienced when it comes to threading, and GThreads is
the thing I want to use, since (I assume) it's quite portable.

I have a function that returns a gfloat and I call the function
sequentially and accumulate the total.
Like this:

/* My sequential pseudo code */
data_t data[N_DATAPOINTS];
gfloat tot_err = 0.0f;
guint i;

fill_the_data_array( data );

for ( i = 0; i < N_DATAPOINTS; i++ )
    tot_err += calc_error( &data[i] );

/* End of my sequential pseudo code */

I have the impression that this should be rather simple to thread
for-loop. Since addition is commutative, I may not even need a mutex
for the tot_err variable.

Can anyone point me in the right direction?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]