Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2006-10-24 20:58:37


On Oct 24, 2006, at 6:42 PM, Peter Dimov wrote:

> Various. Here's the test:

So this is a great test. But the one thing it doesn't test is
starvation. And I'm not sure how to quantify that in an automatic
test either. I'd love to see this test augmented along the lines of:

void clearscr()
{
     std::cerr << "\033[2J";
}

void gotoxy(int row, int col)
{
     std::ostringstream out;
     out << "\033[" << row << ';' << col << 'H';
     std::cerr << out.str();
}

void reader( int r )
{
     for( int i = 0; i < N; ++i )
     {
         if ((i+1) % (n/100) == 0)
         {
             boost::mutex::scoped_lock lock( cmx );
             gotoxy(r, 0);
             std::cerr << "read thread "<< r << " at " << (float)(i
+1)/n * 100 << '%';
             gotoxy(30,0);
         }

         rw_mutex::scoped_read_lock lock( mtx );

         int m = v.front();

         for( std::vector<int>::const_iterator i = v.begin(), end =
v.end(); i != end; ++i )
         {
             assert( *i == m );
         }
     }

     boost::mutex::scoped_lock lock( cmx );
     std::cout << " R" << r;
}

I don't know how to quantify it, but there is nothing quite like the
warm fuzzy of seeing this on your screen:

writ thread 1 at 62%
writ thread 2 at 63%
writ thread 3 at 59%
writ thread 4 at 58%
read thread 5 at 62%
read thread 6 at 55%
read thread 7 at 64%
read thread 8 at 75%

I.e. No thread is getting starved. All are successfully competing
for their fair share. I'd love to see this type of measure
quantified. If all writer threads run before all reader threads, or
vice-versa, I don't care how fast it runs, it's not good.

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk