Have you tried with --fair-sched=yes, as suggested in an earlier mail ?
What were/are the results ?

When I tried it, then --fair-sched=yes gave even more lop-sided results than 
without.
I used 2 threads, with slice size of m_nStep = 16 rasters, and kept track of 
how many
slices were processed by each thread.  Without --fair-sched=yes, then the 
division
was mostly 43 versus 50 or closer, with a few 93 versus 0.  With 
--fair-sched=yes,
then the division was often 93 versus 0, with fewer 40 versus 53 or closer.
(Core i5-2500K CPU @ 3.30GHz; 4 cores, otherwise "idle")
I have never encountered the extremely-slow "hang" that the original post 
described.

This code below takes 31 seconds elapsed bare, and 36 seconds elapsed under 
valgrind.
The charged CPU time is 119 seconds bare, 35 seconds under valgrind.
Actual hardware contention is brutally slow.

===== build with:  g++ -g -O sync-fetch-and-add.cpp -lpthread
#include <pthread.h>

int m_nCurrent;

void *
start_th(void *argstr)  // top-level function for thread
{
    unsigned t = 0;
    for (unsigned j = 0; j < 1000*1000; ++j) {
        t += __sync_fetch_and_add(&m_nCurrent, 0x1);
    }
    return (void *)(long)t;
}

pthread_t thread1, thread2, thread3, thread4;

int
main(int argc, char *argv[])
{
    for (unsigned j=0; j < 400; ++j) {
        m_nCurrent = 0;  // start over each time
        int rv1 = pthread_create(&thread1, NULL, start_th, 0);
        int rv2 = pthread_create(&thread2, NULL, start_th, 0);
        int rv3 = pthread_create(&thread3, NULL, start_th, 0);
        int rv4 = pthread_create(&thread4, NULL, start_th, 0);

        void *res1, *res2, *res3, *res4;
        int rvE1 = pthread_join(thread1, &res1);
        int rvE2 = pthread_join(thread2, &res2);
        int rvE3 = pthread_join(thread3, &res3);
        int rvE4 = pthread_join(thread4, &res4);
    }
    return 0;
}
=====

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to