#include <boost/thread.hpp>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int rows;
int cols;
double **a;
int nthreads;

boost::mutex rand_mtx;

void worker(int tid){
        for (int i=tid;i<rows;i+=nthreads){
                 for(int j=0;j<cols;j++){
                         double value;
                         rand_mtx.lock();
                         value=(double) rand()/(RAND_MAX *1.0);
                         rand_mtx.unlock();
                         a[i][j]=value;
                 }
       }
}
int main() {
        srand(time(0));
        rows=1000;
        cols=1000000;
        nthreads=100; //1+rand()%6;
        //double **a;
        a=new double*[rows];
        for (int i=0;i<rows;i++) {
                 a[i]=new double[cols];
        }
        boost::thread_group tg;
        for(int t=0; t<nthreads;t++) {
                 tg.create_thread(boost::bind(worker,t));
        }
        tg.join_all();
/*        for(int i=0;i<rows;i++){
                for(int j=0;j<cols;j++){
                        cout<<a[i][j] << "";
                }
                cout <<endl;
       }
/*       
       return 0;

}
