Beispiel #1
0
int main()
{
  {
    L1 lk(m0);
    boost::thread t(f);
    BOOST_TEST(test1 == 0);
    while (test1 == 0)
      cv.wait(lk);
    BOOST_TEST(test1 != 0);
    test2 = 1;
    lk.unlock();
    cv.notify_one();
    t.join();
  }
  test1 = 0;
  test2 = 0;
  {
    L1 lk(m0);
    boost::thread t(f);
    BOOST_TEST(test1 == 0);
    while (test1 == 0)
      cv.wait(lk);
    BOOST_TEST(test1 != 0);
    lk.unlock();
    t.join();
  }

  return boost::report_errors();
}
Beispiel #2
0
void my_search::process(int proc_num){
	vector<int> cur_ch;
	vector<int> words;
	int i=0,word_size;
	while(argv[proc_num+1][i]!=0)i++;
	word_size=i;
	words.resize(argc-4);
	cur_ch.resize(argc-4);
	while(counter_file<max_file){
		boost::lock_guard<boost::mutex> lock(m);
		while((counter==0)||(thr[proc_num]==false)){
			if(counter_file>=max_file)return;
			cv.wait(m);
		}
		pantheios::log_NOTICE(PSTR("Reading thread id: ["), pantheios::threadId, PSTR("]"));
		 for(unsigned int c=0;c<memblock.size();c++){
			 char i=memblock[c];
			if(argv[proc_num+1][cur_ch[file_num]]==i)
				cur_ch[file_num]++;
			else cur_ch[file_num]=0;
			if(cur_ch[file_num]==word_size){
				words[file_num]++;sum++;cur_ch[file_num]=0;
			}
		}
		counter--;
		thr[proc_num]=false;
		if(comp_size[file_num]==0){
			cout<<argv[file_num+4]<<" "<<argv[proc_num+1]<<
					" "<<words[file_num]<<endl;
			counter_file++;
		}
		cv.notify_all();
	}
	return;
}
Beispiel #3
0
 count_type wait()
 {
   all_futures_lock lk(waiters_);
   for (;;)
   {
     for (count_type i = 0; i < waiters_.size(); ++i)
     {
       if (waiters_[i].future_->is_ready(lk.locks[i]))
       {
         return waiters_[i].index;
       }
     }
     cv.wait(lk);
   }
 }
Beispiel #4
0
 void put(int x)
 {
     {
         boost::mutex::scoped_lock lock(mu);
         while (is_full())
         {
             {
                 boost::mutex::scoped_lock lock(io_mu);
                 cout << "full waiting..." << endl;
             }
             cond_put.wait(mu);
         }
         stk.push(x);
         ++un_read;
     }
     cond_get.notify_one();
 }
Beispiel #5
0
 void get(int *x)
 {
     {
         boost::mutex::scoped_lock lock(mu);
         while (is_empty())
         {
             {
                 boost::mutex::scoped_lock lock(io_mu);
                 cout << "empty waiting..." << endl;
             }
             cond_get.wait(mu);
         }
         --un_read;
         *x = stk.top();
         stk.pop();
     }
     cond_put.notify_one();
 }
Beispiel #6
0
void my_search:: loadfile(int fl_num){
	file[fl_num].open(argv[fl_num+4], ios::in|ios::binary|ios::ate);
	if (file[fl_num].is_open())
	{
		comp_size[fl_num] = file[fl_num].tellg();
		file[fl_num].seekg (0, ios::beg);
		while(comp_size[fl_num]>0){
			boost::lock_guard<boost::mutex> lock(m);
			while(counter!=0){
				cv.wait(m);
			}
			pantheios::log_NOTICE(PSTR("Writing thread id: ["), pantheios::threadId, PSTR("]"));
			if(comp_size[fl_num]<1024){
				file[fl_num].read (mem, comp_size[fl_num]);
				memblock=mem;
				memblock.resize(comp_size[fl_num]);
				comp_size[fl_num]=0;
			}else {
				file[fl_num].read (mem, 1024);
				memblock=mem;
				memblock.resize(1024);
				comp_size[fl_num]-=1024;
			}
			counter=3;
			file_num=fl_num;
			for (int cc=0;cc<3;cc++)thr[cc]=true;
			cv.notify_all();
		}
		file[fl_num].close();
	}else {
		boost::lock_guard<boost::mutex> lock(m);
		cout << "Unable to open file "<<argv[fl_num+4]<<endl;
		counter_file+=3;
		cv.notify_all();
	}
	return;
}