コード例 #1
0
void test_try_sharable_mutex()
{
   SM mtx;

   data<SM> s1(1);
   data<SM> e1(2);
   data<SM> e2(3);

   // We start with some specialized tests for "try" behavior

   shared_val = 0;

   // Writer one launches, holds the lock for 3*BaseSeconds seconds.

   boost::thread tw1(thread_adapter<SM>(try_exclusive,&e1,mtx));

   // Reader one launches, "clearly" after writer #1 holds the lock
   //   and before it releases the lock.
   boost::thread::sleep(xsecs(1*BaseSeconds));
   boost::thread thr1(thread_adapter<SM>(try_shared,&s1,mtx));

   // Writer two launches in the same timeframe.
   boost::thread tw2(thread_adapter<SM>(try_exclusive,&e2,mtx));

   tw2.join();
   thr1.join();
   tw1.join();

   BOOST_INTERPROCES_CHECK(e1.m_value == 10);
   BOOST_INTERPROCES_CHECK(s1.m_value == -1);        // Try would return w/o waiting
   BOOST_INTERPROCES_CHECK(e2.m_value == -1);        // Try would return w/o waiting
}
コード例 #2
0
ファイル: dsw_iface.cpp プロジェクト: Zex/e2prom-util-reviced
void try_bscu_eeprom()
{
	std::string entry = "bscu";
	TyplWrap tw2(entry);

	std::string  EEPROMSize,  PartNumber,
	 HwCode,  ProductIndex,
	 SerialNumber,  ProductDate,
	 ReadCode,  TestInstruction,
	 BoardName;
		
	std::cout << "ALIGNMENT = " << 
		tw2.getParameterHeaderSection(
		 EEPROMSize, PartNumber,
		 HwCode, ProductIndex,
		 SerialNumber, ProductDate,
		 ReadCode, TestInstruction,
		 BoardName) << '\n';

	std::cout << "EEPROMSIZE = " << EEPROMSize << '\n'
		<< "PARTNUMBER = " <<  PartNumber << '\n'
		<< "HWCODE = " << HwCode << '\n'
		<< "PRODUCTINDEX = " << ProductIndex << '\n'
		<< "SN = " << SerialNumber << '\n'
		<< "PRODUCTDATE = "<< ProductDate << '\n'
		<< "READCODE = " << ReadCode << '\n'
		<< "TESTINSTRUCTION = " << TestInstruction << '\n'
		<< "BOARDNAME = " <<  BoardName << '\n';
}
コード例 #3
0
void TestMacros::TestStreams() {

  I1   i1(0);
  I2   ie(1);
  UW1  uw1(2);
  UW2  uw2(3);
  TW1  tw1(4);
  TW2  tw2(5);
  O1   o1(6);
  O2   o2(7);
}
void test_timed_sharable_mutex()
{
   SM m1, m2, m3, m4;
   SM *pm1, *pm2, *pm3, *pm4;

   if(SameObject){
      pm1 = pm2 = pm3 = pm4 = &m1;
   }
   else{
      pm1 = &m1;
      pm2 = &m2;
      pm3 = &m3;
      pm4 = &m4;
   }
   data<SM> s1(1,1*BaseSeconds);
   data<SM> s2(2,3*BaseSeconds);
   data<SM> e1(3,3*BaseSeconds);
   data<SM> e2(4,1*BaseSeconds);

   // We begin with some specialized tests for "timed" behavior

   shared_val = 0;

   // Writer one will hold the lock for 3*BaseSeconds seconds.
   boost::thread tw1(thread_adapter<SM>(timed_exclusive,&e1,*pm1));

   boost::thread::sleep(xsecs(1*BaseSeconds));
   // Writer two will "clearly" try for the lock after the readers
   //  have tried for it.  Writer will wait up 1*BaseSeconds seconds for the lock.
   //  This write will fail.
   boost::thread tw2(thread_adapter<SM>(timed_exclusive,&e2,*pm2));

   // Readers one and two will "clearly" try for the lock after writer
   //   one already holds it.  1st reader will wait 1*BaseSeconds seconds, and will fail
   //   to get the lock.  2nd reader will wait 3*BaseSeconds seconds, and will get
   //   the lock.

   boost::thread thr1(thread_adapter<SM>(timed_shared,&s1,*pm3));
   boost::thread thr2(thread_adapter<SM>(timed_shared,&s2,*pm4));

   tw1.join();
   thr1.join();
   thr2.join();
   tw2.join();

   assert(e1.m_value == 10);
   assert(s1.m_value == -1);
   assert(s2.m_value == 10);
   assert(e2.m_value == -1);
}
void test_try_sharable_mutex()
{
   SM m1, m2, m3;
   SM *pm1, *pm2, *pm3;

   if(SameObject){
      pm1 = pm2 = pm3 = &m1;
   }
   else{
      pm1 = &m1;
      pm2 = &m2;
      pm3 = &m3;
   }
   data<SM> s1(1);
   data<SM> e1(2);
   data<SM> e2(3);

   // We start with some specialized tests for "try" behavior

   shared_val = 0;

   // Writer one launches, holds the lock for 3*BaseSeconds seconds.

   boost::thread tw1(thread_adapter<SM>(try_exclusive,&e1,*pm1));

   // Reader one launches, "clearly" after writer #1 holds the lock
   //   and before it releases the lock.
   boost::thread::sleep(xsecs(1*BaseSeconds));
   boost::thread thr1(thread_adapter<SM>(try_shared,&s1,*pm2));

   // Writer two launches in the same timeframe.
   boost::thread tw2(thread_adapter<SM>(try_exclusive,&e2,*pm3));

   tw2.join();
   thr1.join();
   tw1.join();

   assert(e1.m_value == 10);
   assert(s1.m_value == -1);        // Try would return w/o waiting
   assert(e2.m_value == -1);        // Try would return w/o waiting
}
コード例 #6
0
ファイル: dsw_iface.cpp プロジェクト: Zex/e2prom-util-reviced
void try_bcb_bin()
{
	std::string entry = "bcb";

	std::string buf;
	std::ifstream ifs;
	ifs.open("bcb.bin", std::ios::binary);
	std::getline(ifs, buf);
	UnpackTypl ty(buf.data());
//-------------testing cache--------------------
	ty.update_cache("bcb", 64*1024);
//------------end testing cache-----------------
	ty.start();
	ifs.close();

	TyplWrap tw2(entry);

	std::string  EEPROMSize,  PartNumber,
	 HwCode,  ProductIndex,
	 SerialNumber,  ProductDate,
	 ReadCode,  TestInstruction,
	 BoardName;
		
	std::cout << "ALIGNMENT = " << 
		tw2.getParameterHeaderSection(
		 EEPROMSize, PartNumber,
		 HwCode, ProductIndex,
		 SerialNumber, ProductDate,
		 ReadCode, TestInstruction,
		 BoardName) << '\n';

	std::cout << "EEPROMSIZE = " << EEPROMSize << '\n'
		<< "PARTNUMBER = " <<  PartNumber << '\n'
		<< "HWCODE = " << HwCode << '\n'
		<< "PRODUCTINDEX = " << ProductIndex << '\n'
		<< "SN = " << SerialNumber << '\n'
		<< "PRODUCTDATE = "<< ProductDate << '\n'
		<< "READCODE = " << ReadCode << '\n'
		<< "TESTINSTRUCTION = " << TestInstruction << '\n'
		<< "BOARDNAME = " <<  BoardName << '\n';
}
コード例 #7
0
void test_timed_sharable_mutex()
{
   SM mtx;
   data<SM> s1(1,1*BaseSeconds);
   data<SM> s2(2,3*BaseSeconds);
   data<SM> e1(3,3*BaseSeconds);
   data<SM> e2(4,1*BaseSeconds);

   // We begin with some specialized tests for "timed" behavior

   shared_val = 0;

   // Writer one will hold the lock for 3*BaseSeconds seconds.
   boost::thread tw1(thread_adapter<SM>(timed_exclusive,&e1,mtx));

   boost::thread::sleep(xsecs(1*BaseSeconds));
   // Writer two will "clearly" try for the lock after the readers
   //  have tried for it.  Writer will wait up 1*BaseSeconds seconds for the lock.
   //  This write will fail.
   boost::thread tw2(thread_adapter<SM>(timed_exclusive,&e2,mtx));

   // Readers one and two will "clearly" try for the lock after writer
   //   one already holds it.  1st reader will wait 1*BaseSeconds seconds, and will fail
   //   to get the lock.  2nd reader will wait 3*BaseSeconds seconds, and will get
   //   the lock.

   boost::thread thr1(thread_adapter<SM>(timed_shared,&s1,mtx));
   boost::thread thr2(thread_adapter<SM>(timed_shared,&s2,mtx));

   tw1.join();
   thr1.join();
   thr2.join();
   tw2.join();

   BOOST_INTERPROCES_CHECK(e1.m_value == 10);
   BOOST_INTERPROCES_CHECK(s1.m_value == -1);
   BOOST_INTERPROCES_CHECK(s2.m_value == 10);
   BOOST_INTERPROCES_CHECK(e2.m_value == -1);
}
コード例 #8
0
void test_plain_sharable_mutex()
{
   {
      shared_val = 0;
      SM mtx;
      data<SM> s1(1);
      data<SM> s2(2);
      data<SM> e1(1);
      data<SM> e2(2);

      // Writer one launches, holds the lock for 3*BaseSeconds seconds.
      boost::thread tw1(thread_adapter<SM>(plain_exclusive, &e1, mtx));

      // Writer two launches, tries to grab the lock, "clearly"
      //  after Writer one will already be holding it.
      boost::thread::sleep(xsecs(1*BaseSeconds));
      boost::thread tw2(thread_adapter<SM>(plain_exclusive, &e2, mtx));

      // Reader one launches, "clearly" after writer two, and "clearly"
      //   while writer 1 still holds the lock
      boost::thread::sleep(xsecs(1*BaseSeconds));
      boost::thread thr1(thread_adapter<SM>(plain_shared,&s1, mtx));
      boost::thread thr2(thread_adapter<SM>(plain_shared,&s2, mtx));

      thr2.join();
      thr1.join();
      tw2.join();
      tw1.join();

      //We can only assure that the writer will be first
      BOOST_INTERPROCES_CHECK(e1.m_value == 10);
      //A that we will execute all
      BOOST_INTERPROCES_CHECK(s1.m_value == 20 || s2.m_value == 20 || e2.m_value == 20);
   }

   {
      shared_val = 0;
      SM mtx;

      data<SM> s1(1, 3);
      data<SM> s2(2, 3);
      data<SM> e1(1);
      data<SM> e2(2);

      //We launch 2 readers, that will block for 3*BaseTime seconds
      boost::thread thr1(thread_adapter<SM>(plain_shared,&s1, mtx));
      boost::thread thr2(thread_adapter<SM>(plain_shared,&s2, mtx));

      //Make sure they try to hold the sharable lock
      boost::thread::sleep(xsecs(1*BaseSeconds));

      // We launch two writers, that should block until the readers end
      boost::thread tw1(thread_adapter<SM>(plain_exclusive,&e1, mtx));
      boost::thread tw2(thread_adapter<SM>(plain_exclusive,&e2, mtx));

      thr2.join();
      thr1.join();
      tw2.join();
      tw1.join();

      //We can only assure that the shared will finish first...
      BOOST_INTERPROCES_CHECK(s1.m_value == 0 || s2.m_value == 0);
      //...and writers will be mutually excluded after readers
      BOOST_INTERPROCES_CHECK((e1.m_value == 10 && e2.m_value == 20) ||
             (e1.m_value == 20 && e2.m_value == 10) );
   }
}
void test_plain_sharable_mutex()
{
   {
      shared_val = 0;
      SM m1, m2, m3, m4;
      SM *pm1, *pm2, *pm3, *pm4;

      if(SameObject){
         pm1 = pm2 = pm3 = pm4 = &m1;
      }
      else{
         pm1 = &m1;
         pm2 = &m2;
         pm3 = &m3;
         pm4 = &m4;
      }
      data<SM> s1(1);
      data<SM> s2(2);
      data<SM> e1(1);
      data<SM> e2(2);

      // Writer one launches, holds the lock for 3*BaseSeconds seconds.
      boost::thread tw1(thread_adapter<SM>(plain_exclusive, &e1, *pm1));

      // Writer two launches, tries to grab the lock, "clearly"
      //  after Writer one will already be holding it.
      boost::thread::sleep(xsecs(1*BaseSeconds));
      boost::thread tw2(thread_adapter<SM>(plain_exclusive, &e2, *pm2));

      // Reader one launches, "clearly" after writer two, and "clearly"
      //   while writer 1 still holds the lock
      boost::thread::sleep(xsecs(1*BaseSeconds));
      boost::thread thr1(thread_adapter<SM>(plain_shared,&s1, *pm3));
      boost::thread thr2(thread_adapter<SM>(plain_shared,&s2, *pm4));

      thr2.join();
      thr1.join();
      tw2.join();
      tw1.join();

      //We can only assure that the writer will be first
      assert(e1.m_value == 10);
      //A that we will execute all
      assert(s1.m_value == 20 || s2.m_value == 20 || e2.m_value == 20);
   }

   {
      shared_val = 0;
      SM m1, m2, m3, m4;
      SM *pm1, *pm2, *pm3, *pm4;

      if(SameObject){
         pm1 = pm2 = pm3 = pm4 = &m1;
      }
      else{
         pm1 = &m1;
         pm2 = &m2;
         pm3 = &m3;
         pm4 = &m4;
      }
      data<SM> s1(1, 3);
      data<SM> s2(2, 3);
      data<SM> e1(1);
      data<SM> e2(2);

      //We launch 2 readers, that will block for 3*BaseTime seconds
      boost::thread thr1(thread_adapter<SM>(plain_shared,&s1,*pm1));
      boost::thread thr2(thread_adapter<SM>(plain_shared,&s2,*pm2));

      //Make sure they try to hold the sharable lock
      boost::thread::sleep(xsecs(1*BaseSeconds));

      // We launch two writers, that should block until the readers end
      boost::thread tw1(thread_adapter<SM>(plain_exclusive,&e1,*pm3));
      boost::thread tw2(thread_adapter<SM>(plain_exclusive,&e2,*pm4));

      thr2.join();
      thr1.join();
      tw2.join();
      tw1.join();

      //We can only assure that the shared will finish first...
      assert(s1.m_value == 0 || s2.m_value == 0);
      //...and writers will be mutually excluded after readers
      assert((e1.m_value == 10 && e2.m_value == 20) || 
             (e1.m_value == 20 && e2.m_value == 10) );
   }
}