int main()
{
    // Create module
    module1 = new ContinuousControlManager("ContinuousControl:Manager");

    //Dummy test interface
    //dummyIface = new ContinuousControlInterface("DummyIface");

    // Debug
    DEBUG(LEVEL_INFO, "Created!");

    // Connect
    //dummyIface->q_out_ = &module1->interface->q_in;
    //module1->interface->q_out_ = &dummyIface->q_in;

    // Run module
    boost::thread th1( boost::bind( &ContinuousControlManager::Run, module1) );
    boost::thread th2( testThread ) ;

    // Wait for threads to end
    th1.join();
    th2.join();
    return 0;

}
int main (int argc, char**argv)
{
  std::cout << "\nwithout lock:\n";
  std::thread th1 (print_block,50,'*');
  std::thread th2 (print_block,50,'$');

  th1.join();
  th2.join();

  std::cout << "\nwith unique_lock:\n";
  std::thread th3 (print_block_lock_guard,50,'*');
  std::thread th4 (print_block_lock_guard,50,'$');

  th3.join();
  th4.join();

  std::cout << "\nwith lock_guard:\n";
  std::thread th5 (print_block_unique_lock,50,'*');
  std::thread th6 (print_block_unique_lock,50,'$');

  th5.join();
  th6.join();

  return 0;
}
Пример #3
0
void testThread()
{
	char arg1[] = "th1";
	char arg2[] = "th2";

	Thread th1((Thread::Routine)foo, arg1);
	Thread th2((Thread::Routine)foo, arg2);

	th1.setBackground(true);
	th1.start();
	th2.start();

#ifdef _WIN32
	Thread::sleep(500);
	th1.suspend();
	LOGT("th1 was suspended.");

	Thread::sleep(500);
	th2.suspend();
	LOGT("th2 was suspended.");

	Thread::sleep(500);
	th1.resume();
	LOGT("th1 was resumed.");

	Thread::sleep(500);
	th2.resume();
	LOGT("th2 was resumed.");
#endif

	int ret2 = th2.join();

	LOG_VAR(ret2);
}
Пример #4
0
int main(){
	boost::thread th1(boost::bind(&push, 0)), th2(pop);
	th1.join();
	th2.join();

	return 1;
}
Пример #5
0
int main()
{
	try
	{
		boost::barrier tb( 2);
		boost::fibers::spin::barrier fb( 2);

		std::cout << "start" << std::endl;

		boost::thread th1( boost::bind( & f, boost::ref( tb), boost::ref( fb) ) );
		boost::thread th2( boost::bind( & g, boost::ref( tb), boost::ref( fb) ) );

		th1.join();
		th2.join();

		std::cout << "finish" << std::endl;

		return EXIT_SUCCESS;
	}
	catch ( boost::system::system_error const& e)
	{ std::cerr << "system_error: " << e.code().value() << std::endl; }
	catch ( boost::fibers::scheduler_error const& e)
	{ std::cerr << "scheduler_error: " << e.what() << std::endl; }
	catch ( std::exception const& e)
	{ std::cerr << "exception: " << e.what() << std::endl; }
	catch (...)
	{ std::cerr << "unhandled exception" << std::endl; }
	return EXIT_FAILURE;
}
Пример #6
0
void
function()
{
  SmartPtr<Derived>  myObj = new Derived();

  Dummy th1(myObj);		    // Doesn't work under Cygnus
  Dummy th2((Base0 *) myObj);	    // Doesn't work either
}
Пример #7
0
int main() {
	std::thread th1(print_block, 50, '*');
	std::thread th2(print_block, 50, '$');

	th1.join();
	th2.join();

	return 0;
}
Пример #8
0
int main()
{
    queue<int> q;
    std::thread th1(push,&q);
    std::thread th2(pop,&q);
    th1.join();
    th2.join();
    return 0;
}
Пример #9
0
int main()
{
	std::thread th1([]{ rnd_fkt(1); });
	std::thread th2([]{ rnd_fkt(2); });

	th1.join();
	th2.join();
	return 0;
}
Пример #10
0
int main(){
	std::thread th1(print_foo);
	std::thread th2(set_foo, 10);

	th1.join();
	th2.join();

	return 0;
}
Пример #11
0
int main ()
{
  Hx::thread th1 (task_a);
  Hx::thread th2 (task_b);

  th1.join();
  th2.join();

  return 0;
}
Пример #12
0
int main()
{

  boost::thread th1(&do_thread);
  th1.join();

  //std::string s1;
  //std::cin >> s1;

  return boost::report_errors();
}
FileSystem::FileSystem(int port, Membership& m) :
    membership(m), port(port)
{
	logFile.open("logFileSystem.log"); // we can make all the logs going to a single file, but nah.

    std::thread th2(&FileSystem::updateThread, this);
    ringUpdating.swap(th2);

    std::thread th1(&FileSystem::listeningThread, this);
    listening.swap(th1);
}
Пример #14
0
int main()
{
	{
	std::thread th1(print_block, 40, '*');
	std::thread th2(print_block, 40, '$');

	th1.join();
	th2.join();
	}

	std::cout << "=== next run ===========================+\n";
	{
	std::thread th1(print_critial_block, 40, '*');
	std::thread th2(print_critial_block, 40, '$');

	th1.join();
	th2.join();
	}
	return 0;
}
Пример #15
0
int main(){
    boost::mutex mutex;
    Task task1(1, &mutex);
    Task task2(2, &mutex);
	
	boost::thread th1(&Task::run, &task1); 
	boost::thread th2(&Task::run, &task2); 
	th1.join();
	th2.join();	
    return 0;
}
Пример #16
0
void testCondition()
{
	Thread th1((Thread::Routine)changer);
	Thread th2((Thread::Routine)watcher);

	th1.start();
	th2.start();

	th1.join();
	th2.join();
}
Пример #17
0
int main(int argc, char** argv)
{
    int a = 0;
    spinlock spin;
    
    std::thread th1(th_write, std::ref(spin), std::ref(a));
    std::thread th2(th_read, std::ref(spin), std::ref(a));
    
    th1.join();
    th2.join();
    return 0;
}
Пример #18
0
int main(int argc, char** argv)
{
	std::thread th1(print_this);
	std::thread th2(print_this);
	std::thread th3(print_this);
	std::thread th4(print_this);
	th1.join();
	th2.join();
	th3.join();
	th4.join();
	return 0;
}
Пример #19
0
int main()
{
    cv = new std::condition_variable_any;
    std::thread th2(g);
    m.lock();
    while (!g_ready)
        cv->wait(m);
    m.unlock();
    std::thread th1(f);
    th1.join();
    th2.join();
}
int main() {
    std::thread th1(print_block, 20, '*');
    std::thread th2(print_block, 20, '#');
    std::thread th3(print_block, 20, 'a');
    std::thread th4(print_block, 20, '&');
    
    th1.join();
    th2.join();
    th3.join();
    th4.join();
    
    return 0;
}
int main()
{
  std::cout << "//////////////////////////// std::async\n";
  //////////////////////////// std::async
  std::vector<int> data(100);
  // std::iota(std::begin(data), std::end(data));

  //called by function
  std::future<int> result = std::async(accumulate, std::cref(data));  
  std::cout<<result.get()<<std::endl; //#1

  //called by functor
  Accmulate acc;
  std::future<int> result2 = std::async(&Accmulate::operator(), 
                                              &acc, std::cref(data));
  std::cout<<result2.get()<<std::endl; //#2


  std::cout << "//////////////////////////// std::promise\n";
  std::promise<int> pm;

  std::future<int> result3 = pm.get_future();

  std::thread th1 (test, std::ref(result3));

  pm.set_value (10);
                            
  th1.join();

  std::cout << "//////////////////////////// std::packaged_task\n";
    std::vector<std::packaged_task<int(int, int)>> tasks;
    std::vector<std::future<int>> futures;
    for(size_t i = 0; i != 4; ++i){
        std::packaged_task<int(int, int)> task(&max);
        futures.emplace_back(task.get_future());
        tasks.push_back(std::move(task));
    }
    
    //run the tasks asynchronous
    std::thread t1(std::move(tasks[0]), 3, 4);
    std::thread t2(std::move(tasks[1]), 4, 5);
    //run the tasks concurrent
    tasks[2](5, 4);
    tasks[3](3, 2);

    for(auto &data : futures){
        std::cout<<data.get()<<std::endl;
    }
    t1.join();
    t2.join();
}
Пример #22
0
CosmosQueue::CosmosQueue(unsigned int port, unsigned int sendSize, unsigned int recvSize):
    cosmos(port), tlmQueue(), cmdQueue() {
        connected.store(false);
        tlmCapacity = sendSize;
        cmdCapacity = recvSize;
        if (tlmCapacity > 0) {
            std::thread th1(&CosmosQueue::tlm_thread, this);
            th1.detach();
        }
        if (cmdCapacity > 0) {
            std::thread th2(&CosmosQueue::cmd_thread, this);
            th2.detach();
        }
    }
Пример #23
0
int main(int, char**)
{
    cv = new std::condition_variable;
    std::thread th2(g);
    Lock lk(m);
    while (!g_ready)
        cv->wait(lk);
    lk.unlock();
    std::thread th1(f);
    th1.join();
    th2.join();

  return 0;
}
Пример #24
0
void testObj::test<3>(void)
{
  double     data[2]={1, 2};
  Mutex      mutex;
  TestLocker tl1(&mutex, data);
  TestLocker tl2(&mutex, data);

  // start two threads
  Base::Threads::ThreadJoiner th1(tl1);
  Base::Threads::ThreadJoiner th2(tl2);
  // and join them
  th1->join();
  th2->join();
}
Пример #25
0
main()
{
	float a,b,c,d,e,f;
	printf("\nNhap vao a,b,c,d,e,f : ");  scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f);
	dd = a*e - d*b;
	dx = b*f - e*c;
	dy = a*f - d*c;
	if (dd != 0)  
		th1();
	else
		if ((dx == dy)&&(dy == 0))  th2();
		else th3();
	getch();
}
Пример #26
0
int main(){
	boost::thread th1(boost::bind(&insert, 0)), th2(boost::bind(&insert, 1));
	th1.join();
	th2.join();

	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 10000; j++){
			std::string str;
			table.search(j+(i*10000), str);
			std::cout << str << std::endl;
		}
	}

	return 1;
}
Пример #27
0
int main()
{
  cv = new boost::permit_c_any;
  boost::thread th2(g);
  Lock lk(m);
  while (!g_ready)
  {
    cv->wait(lk);
  }
  lk.unlock();
  boost::thread th1(f);
  th1.join();
  th2.join();
  return boost::report_errors();
}
Пример #28
0
int main()
{
  cv = new boost::condition_variable;
  boost::thread th2(g);
  Lock lk(m);
  while (!g_ready)
  {
    cv->wait(lk);
  }
  lk.unlock();
  boost::thread th1(f);
  th1.join();
  th2.join();
  return boost::report_errors();
}
Пример #29
0
int main()
{
    std::thread th1(do_work);
    std::thread th2(do_work);
    std::thread th3(do_work);
    std::thread th4(do_work);
    std::thread th5(do_work);
 
    th1.join();
    th2.join();
    th3.join();
    th4.join();
    th5.join();
 
    std::cout << "Result:" << data << '\n';
}
Пример #30
0
    //Multi-thread with on io_service instance and serval handler threads.
    void test_2() {
        boost::asio::io_service service;

        boost::asio::deadline_timer t1(service, boost::posix_time::seconds(5));
        t1.async_wait(boost::bind(handler, "timer1", _1));
        boost::asio::deadline_timer t2(service, boost::posix_time::seconds(5));
        t2.async_wait(boost::bind(handler, "timer2", _1));
        boost::asio::deadline_timer t3(service, boost::posix_time::seconds(5));
        t3.async_wait(boost::bind(handler, "timer3", _1));
        boost::asio::deadline_timer t4(service, boost::posix_time::seconds(5));
        t4.async_wait(boost::bind(handler, "timer4", _1));

        boost::thread th1([&service]() { service.run(); });
        boost::thread th2([&service]() { service.run(); });
        th1.join();
        th2.join();
    }