Example #1
0
int main()
{
  __CPROVER_ASYNC_1: thr1(0);
  __CPROVER_ASYNC_2: thr2(0);
   __CPROVER_ASYNC_3: thr3(0);
return 0;
}
Example #2
0
int
main(int argc, char** argv)
{
    ThreadFunctor tf;
    std::thread thr(doit);
    std::thread thr2(doit2, 10);
    std::thread thr3(tf);

    thr.join();
    thr2.join();
    thr3.join();

    std::vector<std::thread> threads;
    threads.push_back(std::thread(doit2, 1));
    threads.push_back(std::thread(doit2, 2));
    threads.push_back(std::thread(doit2, 3));

    for (auto &thr:threads) {
        thr.join();
    }

    printf("Nubmer of hardware thread contexts: %u\n", 
        std::thread::hardware_concurrency());
    return 0;
}
Example #3
0
int main( ) {
   boost::thread thr1(sendSomething);
   boost::thread thr2(recvSomething);

   thr1.join( );
   thr2.join( );
}
Example #4
0
File: main.c Project: olivo/BP
int main()
{
  __CPROVER_assume(w==0);
  __CPROVER_assume(r==0);

  __CPROVER_ASYNC_1: thr1();
  thr2();
}
int main()
{
  pthread_t t;

  pthread_create(&t, 0, thr1, 0);
  thr2(0);
  
  return 0;
}
Example #6
0
int main( ) {
   boost::thread thr1(boss);
   boost::thread thr2(worker);
   boost::thread thr3(worker);

   thr1.join( );
   thr2.join( );
   thr3.join( );
}
Example #7
0
int main()
{
  __CPROVER_ASYNC_0: thr0(0);
  __CPROVER_ASYNC_1: thr1(0);
  __CPROVER_ASYNC_2: thr2(0);
//thr2(0);

return 0;
}
Example #8
0
int main()
{
  __CPROVER_ASYNC_0: thr1(0);
  __CPROVER_ASYNC_1: thr2(0);
  __CPROVER_ASYNC_2: thr3(0);
  __CPROVER_ASYNC_3: thr4(0);

  //thr2(0);
}
Example #9
0
int main(){
  // pthread_t t1, t2;
  // pthread_create(&t1, NULL, thr1, NULL);
  // pthread_create(&t2, NULL, thr2, NULL);
__CPROVER_ASYNC_1: thr1(0);
__CPROVER_ASYNC_2: thr2(0);
  assert(r1 != 1 || r2 != 1);
  return 0;
}
int main()
{
  pthread_t t;

  pthread_create(&t, 0, thr1, 0);
  thr2(0);

  /* reachable */
  return 0;
}
int main() {

    std::string s1 = "This is the first thread!";
    std::string s2 = "This is the second thread!";

    boost::thread thr1(Adapter<WorkerFunPtr, std::string>(worker, s1));
    boost::thread thr2(Adapter<WorkerFunPtr, std::string>(worker, s2));

    thr1.join();
    thr2.join();
}
Example #12
0
int main() {
    barrier barr(3);
    
    std::thread thr1(f, std::ref(barr));
    std::thread thr2(f, std::ref(barr));
    std::thread thr3(f, std::ref(barr));
    thr1.join();
    thr2.join();
    thr3.join();
    return 0;
}
Example #13
0
int main()
{
    pthread_t pt1;
     pthread_create(&pt1,0,thr1,0);
      thr2(0);
      pthread_join(pt1,0);
     //assert(counter==(ROUND<<1));
     //assert(sum1+sum2>=0);
	assert(!((finished1 == 1) && (finished2 == 1)) || cs == 2);
//  __CPROVER_ASYNC_1: thr1(0);
//  thr2(0);
}
Example #14
0
int main()
{
  __CPROVER_ASYNC_0: thr0(0);
  __CPROVER_ASYNC_1: thr1(0);
  __CPROVER_ASYNC_2: thr2(0);
  __CPROVER_ASYNC_3: thr3(0);
  __CPROVER_ASYNC_4: thr4(0);
 __CPROVER_ASYNC_5: thr5(0);
//thr2(0);

return 0;
}
Example #15
0
int main()
{
    pthread_t pt1;
     pthread_create(&pt1,0,thr1,0);
      thr2(0);
      pthread_join(pt1,0);
     //assert(counter==(ROUND<<1));
     //assert(sum1+sum2>=0);
	assert((!( r2 == 1) || ( r1 == 1) ) && (!( r4 == 1) || ( r3 == 1)) && (!( r6 == 1) || ( r5 == 1)) && (!( r8 == 1) || ( r7 == 1)) && (!( r10 == 1) || ( r9 == 1)));
//  __CPROVER_ASYNC_1: thr1(0);
//  thr2(0);
}
Example #16
0
int main(int, char **)
{
  State s;
  
  gcore::Thread thr1(&s, &State::run1, &State::done1);
  gcore::Thread thr2(&s, &State::run2, &State::done2);
  
  thr1.join();
  thr1.join();
  
  s.print(stderr, "\nThat's all folks !!\n");

  return 0;
}
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);
}
Example #18
0
	static void test(void)
	{
		atomic_long_test at;
		mythread thr1(at), thr2(at), thr3(at);
		thr1.set_detachable(false);
		thr2.set_detachable(false);
		thr3.set_detachable(false);
		thr1.start();
		thr2.start();
		thr3.start();
		thr1.wait();
		thr2.wait();
		thr3.wait();
	}
Example #19
0
int main()
{
  __CPROVER_ASYNC_0: thr1(0);
  __CPROVER_ASYNC_1: thr2(0);
  __CPROVER_ASYNC_2: thr3(0);
  __CPROVER_ASYNC_3: thr4(0);
  __CPROVER_ASYNC_4: thr5(0);
__CPROVER_ASYNC_5: thr6(0);
__CPROVER_ASYNC_6: thr7(0);
__CPROVER_ASYNC_7: thr8(0);
__CPROVER_ASYNC_8: thr9(0);
__CPROVER_ASYNC_9: thr10(0);

  //thr2(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);
}
Example #21
0
int main (void)
{
  CDUMMY thr1 (1), thr2 (2), thr3 (3);

  thr1.Start ();
  thr2.Start ();
  thr3.Start ();

  while (42)
    {
#ifdef _WIN32
      Sleep (1000);
#else
      struct timeval tv = {2, 0};

      ::select (0, 0x0, 0x0, 0x0, &tv);
#endif

      printf ("%08x %08x %08x\n", thr1._cnt, thr2._cnt, thr3._cnt);
    }

  return 0;
}
Example #22
0
/*----------------------------------------------------------------------------------------------
// This method is called when a Throwable exception is caught at the end of a COM method,
// or (with a dummy ThrowableSd) when some other exception is caught. It transforms the info
// in the Throwable into a standard COM error report (creating an IErrorInfo and registering
// it.) It returns the HRESULT that should be returned by the COM method.

// There are several different situations which this method has to handle. The following
// comments describe the situations, and how they are indicated. Each "indication" presumes
// that the previous "indications" failed.
// 1. We called a COM method which supports IErrorInfo and already provides all the information
//		we need to pass to our own caller. This is indicated by a help ID of -1.
// 2. We, or a method we called that doesn't support IErrorInfo, ran out of memory.
//		We need to set up the special error object pre-created for this case. This is
//		indicated by thr.Error() being E_OUTOFMEMORY.
// 3. A programming error has been caught and a stack dump generated, either in our own code
//		or in the code that called us. This is indicated by finding that thr is actually
//		a ThrowableSd. Make an error object, with a description that includes the stack dump.
----------------------------------------------------------------------------------------------*/
HRESULT HandleThrowable(Throwable & thr, REFGUID iid, DummyFactory * pfact)
{
	StrUni stuDesc;
	HRESULT hrErr = thr.Error();
	HRESULT hr;

	// If we already have error info, we set it again (very likely got cleared by previous
	// CheckHr), and then just return the HRESULT.
	if (thr.GetErrorInfo())
	{
		::SetErrorInfo(0, thr.GetErrorInfo());
		return hrErr;
	}

	// We need a Unicode version of the ProgId, but we should avoid allocating memory
	// since we don't yet know that we have not run out.
	// Since all our progids are in simple ascii, we can do the simplest possible conversion.
	// Since we hopefully have at least a little stack to work with, use _alloca.
	OLECHAR * pszSrc = (OLECHAR *)_alloca((StrLen(pfact->GetProgId()) + 1) * isizeof(OLECHAR));
	OLECHAR * pchw = pszSrc;
	for (const TCHAR * pch = pfact->GetProgId(); *pch; pch++, pchw++)
		*pchw = *pch;
	*pchw = 0;

	if (hrErr == E_OUTOFMEMORY)
	{
		// Use the pre-created error info object so we don't have to allocate now.
		// It already has a description, help file path, and help context ID.
		// If a further E_OUTOFMEMORY occurs calling SetGUID or SetSource, just ignore it.
		s_qcerrinfoMem->SetGUID(iid);
		s_qcerrinfoMem->SetSource(pszSrc);
		SetErrorInfo(0, s_qerrinfoMem);
		return hrErr;
	}

	// Otherwise we are going to make a new error info object.

	// Get any message supplied by the Throwable.
	StrUni stuUserMsg(thr.Message());
	// See if a stack dump is available.
	ThrowableSd * pthrs = dynamic_cast<ThrowableSd *>(&thr);
	char * pchDump = NULL;
	if (pthrs)
		pchDump = const_cast<char *>(pthrs->GetDump());
	else if (!stuUserMsg.Length())
	{
		// If we don't have any sort of nice message, treat it as an internal error.
		DumpStackHere("HandleThrowable caught an error with no description");
		pchDump = const_cast<char *>(StackDumper::GetDump());
	}
	if (pchDump)
	{
		// We have a stack dump.
		StrUni stuModName = ModuleEntry::GetModulePathName();

		// Do we already have a description? If not make one.
		if (!stuUserMsg.Length())
		{
			// No, use a default one.
			StrUni stuHrMsg = ConvertException((DWORD)hrErr);

			StrUni stuUserMsgFmt;
			stuUserMsgFmt.Load(kstidInternalError);
			// Would it be better to strip off the path?
			stuUserMsg.Format(stuUserMsgFmt, stuHrMsg.Chars(), stuModName.Chars());
		}
		stuDesc.Format(L"%s%s%S\r\n\r\n%s", stuUserMsg.Chars(), ThrowableSd::MoreSep(), pchDump,
			GetModuleVersion(stuModName.Chars()).Chars());
	}
	else
	{
		// We've made sure we have a message already; use it.
		stuDesc = stuUserMsg;
	}

	StrUni stuSource(pszSrc);
	hr = StackDumper::RecordError(iid, stuDesc, stuSource, thr.HelpId(),
		GetModuleHelpFilePath());
	if (FAILED(hr))
	{
		if (hr == E_OUTOFMEMORY)
		{
			Throwable thr2(E_OUTOFMEMORY);
			return HandleThrowable(thr2, iid, pfact);
		}

		// just report the failure to the developer
		WarnHr(hr);

		// Hard to know what do do here. It should never happen. For paranoia's sake at least
		// return the original problem.
	}
	return hrErr;
}
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) );
   }
}
Example #24
0
File: main.c Project: olivo/BP
int main()
{
  __CPROVER_ASYNC_1: thr1();
  thr2();
}
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) );
   }
}