Changeset 2933


Ignore:
Timestamp:
Dec 28, 2012, 4:20:58 AM (9 years ago)
Author:
Peter
Message:

avoid transfer exception between threads. Print as early as possible. Flush output more often.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.10-stable/test/rng-mt.cc

    r2881 r2933  
    2929
    3030#include <algorithm>
     31#include <cstdlib>
    3132#include <iostream>
    3233#include <iterator>
     34#include <stdexcept>
    3335#include <vector>
    3436
     
    4446  void operator()(void)
    4547  {
    46     for (std::vector<int>::iterator i=begin_; i!=end_; ++i)
    47       *i = rnd_(100);
     48    try {
     49      for (std::vector<int>::iterator i=begin_; i!=end_; ++i)
     50        *i = rnd_(100);
     51    }
     52    catch (std::exception& e) {
     53      std::cerr << e.what() << "\n";
     54      exit(EXIT_FAILURE);
     55    }
    4856  }
    4957
     
    8795  suite.out() << "\ny: ";
    8896  std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
    89   suite.out() << "\n";
     97  suite.out() << std::endl;
    9098
    9199  if (x==y) {
     
    93101    suite.err() << "x and y are equal\n";
    94102  }
    95 
    96103}
    97104
     
    107114  threads.create_thread(visitor1);
    108115  threads.join_all();
     116  // copy result from visitor1 to variable y
    109117  std::vector<int> y(x);
     118  suite.out() << "y: ";
     119  std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
     120  suite.out() << std::endl;
     121
    110122  RNG::instance()->seed(0);
    111123  threads.create_thread(visitor1);
     
    113125  suite.out() << "x: ";
    114126  std::copy(x.begin(), x.end(), std::ostream_iterator<int>(suite.out(), " "));
    115   suite.out() << "\ny: ";
    116   std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
    117   suite.out() << "\n";
     127  suite.out() << std::endl;
    118128  if (x!=y) {
    119129    suite.add(false);
     
    135145  Visitor visitor(x);
    136146  visitor();
     147  suite.out() << "x: ";
     148  std::copy(x.begin(), x.end(), std::ostream_iterator<int>(suite.out(), " "));
     149  suite.out() << std::endl;
    137150
    138151  std::vector<int> y(x);
     
    142155  threads.join_all();
    143156
    144   suite.out() << "x: ";
    145   std::copy(x.begin(), x.end(), std::ostream_iterator<int>(suite.out(), " "));
    146   suite.out() << "\ny: ";
     157  suite.out() << "y: ";
    147158  std::copy(y.begin(), y.end(), std::ostream_iterator<int>(suite.out(), " "));
    148   suite.out() << "\n";
     159  suite.out() << std::endl;
    149160
    150161  if (x==y) {
Note: See TracChangeset for help on using the changeset viewer.