int main(int argc, char** argv) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " path/to/lena" << std::endl; exit(1); } cv::Mat image, orig, lena, noize, diag, tool; image = cv::imread(argv[1], 1); diag = cv::imread(DIAG, CV_LOAD_IMAGE_GRAYSCALE); orig = cv::imread(ORIG, CV_LOAD_IMAGE_GRAYSCALE); lena = cv::imread(LENA, 1); noize = cv::imread(NOIZE, 1); tool = cv::imread(TOOL, CV_LOAD_IMAGE_GRAYSCALE); std::cout << "Task 1 Status: " << (task1(image) ? "OK" : "Error") << std::endl; std::cout << "Task 2 Status: " << (task2(image) ? "OK" : "Error") << std::endl; std::cout << "Task 3 Status: " << (task3(image) ? "OK" : "Error") << std::endl; std::cout << "Task 4 Status: " << (task4(image) ? "OK" : "Error") << std::endl; std::cout << "Task 5 Status: " << (task5((PATH + "noize/").c_str()) ? "OK" : "Error") << std::endl; std::cout << "Task 6 Status: " << (task6(image) ? "OK" : "Error") << std::endl; std::cout << "Task 3.1 Status: " << (task3_1(orig) ? "OK" : "Error") << std::endl; std::cout << "Task 3.2 Status: " << (task3_2(orig) ? "OK" : "Error") << std::endl; std::cout << "Task 3.3 Status: " << (task3_3(tool) ? "OK" : "Error") << std::endl; std::cout << "Task 3.5 Status: " << (task3_5(diag, orig) ? "OK" : "Error") << std::endl; std::cout << "Task 3.6 Status: " << (task3_6(lena, noize) ? "OK" : "Error") << std::endl; // cv::namedWindow("Lesson 2", CV_WINDOW_NORMAL); // cv::imshow("Lesson 2", image); // cv::waitKey(0); return 0; }
void PriorityTapeTest::testPriority() { boost::posix_time::ptime begin; boost::posix_time::ptime current; int duration; CPPUNIT_ASSERT( true == priority_->Enable(true) ); PriorityTapeTask task0(priority_.get(),100,0,10); PriorityTapeTask task1(priority_.get(),100,1,10); PriorityTapeTask task2(priority_.get(),100,2,10); PriorityTapeTask task3(priority_.get(),100,3,10); PriorityTapeTask task4(priority_.get(),100,4,10); PriorityTapeTask task5(priority_.get(),100,5,10); task0.Start(); boost::this_thread::sleep( boost::posix_time::milliseconds(5) ); task1.Start(); task2.Start(); task3.Start(); task4.Start(); task5.Start(); CPPUNIT_ASSERT( false == task0.Finished() ); CPPUNIT_ASSERT( false == task1.Finished() ); CPPUNIT_ASSERT( false == task2.Finished() ); CPPUNIT_ASSERT( false == task3.Finished() ); CPPUNIT_ASSERT( false == task4.Finished() ); CPPUNIT_ASSERT( false == task5.Finished() ); boost::this_thread::sleep( boost::posix_time::milliseconds(100) ); CPPUNIT_ASSERT( true == task0.Finished() ); CPPUNIT_ASSERT( true == task5.Finished() ); CPPUNIT_ASSERT( true == task4.Finished() ); CPPUNIT_ASSERT( true == task3.Finished() ); CPPUNIT_ASSERT( true == task2.Finished() ); CPPUNIT_ASSERT( true == task1.Finished() ); duration = (task0.End() - task0.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task1.End() - task1.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task2.End() - task2.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task3.End() - task3.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task4.End() - task4.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task5.End() - task5.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); CPPUNIT_ASSERT( task0.End() <= task5.Begin() ); CPPUNIT_ASSERT( task5.End() <= task4.Begin() ); CPPUNIT_ASSERT( task4.End() <= task3.Begin() ); CPPUNIT_ASSERT( task3.End() <= task2.Begin() ); CPPUNIT_ASSERT( task2.End() <= task1.Begin() ); }
int main() { int i, sleepTime; // The condition the threads will be using ArCondition cond; // The threads Task task1(1, &cond); Task task2(2, &cond); Task task3(3, &cond); Task task4(4, &cond); // Initialize Aria, which in turn initializes the thread layer Aria::init(); // Initialize the rand() function srand((unsigned)time(NULL)); // Lets start all correct threads. task1.create(); task2.create(); task3.create(); task4.create(); // Lets wake up the threads at different random times for (i=0; i<10; ++i) { sleepTime=rand()%400+100; printf("Main: Sleeping %dms\n", sleepTime); ArUtil::sleep(sleepTime); printf("Main: Waking up a thread\n"); cond.signal(); } printf("Exiting\n"); // Stop all the threads, which sets their running variable to false ArThread::stopAll(); // Now that all the threads are marked as not running, wake them up // so that we can exit the program gracefully. cond.broadcast(); // Wait for all the threads to exit ArThread::joinAll(); // Uninit Aria Aria::uninit(); return(0); }
int main() { // task 1 std::packaged_task<int(int)> task1(mult2); std::future<int> fut1 = task1.get_future(); task1(3); std::cout << fut1.get() << std::endl; // task 2 std::packaged_task<long(int)> task2(mult2); std::future<long> fut2 = task2.get_future(); task2(4); std::cout << fut2.get() << std::endl; // task 3 std::packaged_task<int(int)> task3(mult2); task3(5); std::future<int> fut3 = task3.get_future(); std::cout << fut3.get() << std::endl; // task 4 std::packaged_task<void()> task4([]{std::cout << "void" << std::endl;}); task4(); task4.get_future().get(); }
int main(int argc, const char * argv[]) { // insert code here... int t; printf("Меню:\n1)Все числа от 1 до n\n2)Все числа от А до В\n3)Функция Аккермана\n4)Точная степень двойки\n5)Сумма цифр числа\n"); printf("Выберите номер задания\n"); scanf("%d",&t); while(t!=6) { switch(t) { case 1: { printf("Все числа от 1 до n\n"); task1(); break; } case 2: { printf("Все числа от А до В\n"); task2(); break; } case 3: { printf("Функция Аккермана\n"); task3(); break; } case 4: { printf("Точная степень двойки\n"); task4(); break; } case 5: { printf("Сумма цифр числа\n"); task5(); break; } } printf("\nМеню:\n1)Все числа от 1 до n\n2)Все числа от А до В\n3)Функция Аккермана\n4)Точная степень двойки\n5)Сумма цифр числа\n"); printf("Выберите номер задания\n"); scanf("%d",&t); } return 0; }
void runTestMulti() { #if defined(DEBUG) os::diag::trace.putString(__PRETTY_FUNCTION__); os::diag::trace.putNewLine(); #endif ts.setClassName("os::core::Thread"); ts.setFunctionNameOrPrefix("sleep()"); Task task1("T1", hal::arch::MIN_STACK_SIZE); Task task2("T2", hal::arch::MIN_STACK_SIZE); Task task3("T3", hal::arch::MIN_STACK_SIZE); Task task4("T4", hal::arch::MIN_STACK_SIZE); Task task5("T5", hal::arch::MIN_STACK_SIZE); Task* taskArray[5] = { &task1, &task2, &task3, &task4, &task5 }; for (auto pTask : taskArray) { ts.setPreconditions(pTask->getName()); ts.assertCondition(pTask->getCount() == 0); } for (auto pTask : taskArray) { ts.assertCondition(pTask->getThread().start()); } for (auto pTask : taskArray) { pTask->getThread().join(); } for (auto pTask : taskArray) { ts.setPreconditions(pTask->getName()); ts.assertCondition( ((pTask->getDeltaTicks() - pTask->getCount()) <= pTask->getSleepCalls())); } }
void Scheduler_ut::test_tasks() { IPRINTF("\nExecuting %s\n", __func__); /* Create the tasks. */ Task_properties tprops; tprops.period = units::Nanoseconds(20 * units::MSEC); tprops.prio = higher_priority; Test_task task1("task_2_1", 1); CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task1.is_valid()); tprops.prio = lower_priority; Test_task task2("task_2_2", 2); CPPUNIT_ASSERT_EQUAL(true, task2.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task2.is_valid()); tprops.period = units::Nanoseconds(10 * units::MSEC); tprops.prio = highest_priority; Test_task task3("task_1_3", 3); CPPUNIT_ASSERT_EQUAL(true, task3.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task3.is_valid()); tprops.period = units::Nanoseconds(40 * units::MSEC); tprops.prio = lowest_priority; Test_task task4("task_4_4", 4); CPPUNIT_ASSERT_EQUAL(true, task4.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task4.is_valid()); /* Set up this task with invalid period (faster than the scheduler). */ tprops.period = units::Nanoseconds(sched_period / 2); tprops.prio = lowest_priority; Test_task task5("task_invalid_period", 5); CPPUNIT_ASSERT_EQUAL(true, task5.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task5.is_valid()); /* Runtimes should be zero before the task starts. */ units::Nanoseconds last_runtime = task1.get_last_runtime(); CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), last_runtime); CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), task1.get_max_runtime()); /* Off to the races. */ task_terminated = false; CPPUNIT_ASSERT_EQUAL(true, task1.start()); CPPUNIT_ASSERT_EQUAL(true, task2.start()); CPPUNIT_ASSERT_EQUAL(true, task3.start()); CPPUNIT_ASSERT_EQUAL(true, task4.start()); IPRINTF("\nTesting invalid period, an error is expected\n"); CPPUNIT_ASSERT_EQUAL(false, task5.start()); /* Not the most reliable timing method. */ sleep(units::Nanoseconds(1 * units::SEC)); /* Stop the tasks so the counters stop incrementing. This makes * cleanup faster too. */ DPRINTF("Halting all test tasks\n"); DPRINTF("Stopping task 1\n"); task1.stop(); DPRINTF("Stopping task 2\n"); task2.stop(); DPRINTF("Stopping task 3\n"); task3.stop(); DPRINTF("Stopping task 4\n"); task4.stop(); CPPUNIT_ASSERT_EQUAL(true, task_terminated); /* Check the counters to see if the counts match. Allow some variance * to account for the imprecision of halting the task based on a * timer. */ CPPUNIT_ASSERT((counter[1] >= 48) && (counter[1] <= 60)); CPPUNIT_ASSERT((counter[2] >= 48) && (counter[2] <= 60)); CPPUNIT_ASSERT((counter[3] >= 98) && (counter[3] <= 110)); CPPUNIT_ASSERT((counter[4] >= 23) && (counter[4] <= 35)); /* Check that the runtimes are reasonable. */ last_runtime = task1.get_last_runtime(); IPRINTF("last_runtime = %" PRId64 "\n", int64_t(last_runtime)); CPPUNIT_ASSERT(last_runtime > units::Nanoseconds(0)); CPPUNIT_ASSERT(task1.get_max_runtime() >= last_runtime); }
// // a task gets dispatched on every tick_flag tick (10ms) // void task_dispatch(void) { /* scan the task bits for an active task and execute it */ char task; /* take care of the task timers. if the value ==0 skip it else decrement it. If it decrements to zero, activate the task associated with it */ task=0; while (task < NUM_TASKS ) { if (task_timers[task]) { task_timers[task]--; /* dec the timer */ if (task_timers[task] == 0 ) { set_task(task); /* if ==0 activate the task bit */ } } task++; } task = 0; /* start at the most significant task */ while (task <= NUM_TASKS ) { if ((task_bits & pgm_read_byte(&bit_mask[task]))) { break; /* if activate task found..*/ } task++; /* else try the next one */ } switch(task) /* if task bit is active..execute the task */ { case 0: task0(); break; case 1: task1(); break; case 2: task2(); break; case 3: task3(); break; case 4: task4(); break; case 5: task5(); break; case 6: task6(); break; case 7: task7(); break; default: break; /* no task was active!! */ } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Resolve HomeFinder interface CORBA::Object_var obj1 = orb->string_to_object (ior1); CORBA::Object_var obj2 = orb->string_to_object (ior2); CORBA::Object_var obj3 = orb->string_to_object (ior3); CORBA::Object_var obj4 = orb->string_to_object (ior4); if (CORBA::is_nil (obj1.in ()) || CORBA::is_nil (obj2.in ()) || CORBA::is_nil (obj3.in ()) || CORBA::is_nil (obj4.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Nil Benchmark::RoundtripClient reference\n"), 1); } //Narrow to appropriate interfaces Benchmark::RoundTripClient_var client1= Benchmark::RoundTripClient::_narrow (obj1.in()); Benchmark::RoundTripClient_var client2= Benchmark::RoundTripClient::_narrow (obj1.in()); Benchmark::RoundTripClient_var client3= Benchmark::RoundTripClient::_narrow (obj1.in()); Benchmark::RoundTripClient_var client4= Benchmark::RoundTripClient::_narrow (obj1.in()); //Create Tasks Client_Task task1(client1.in()); Client_Task task2(client2.in()); Client_Task task3(client3.in()); Client_Task task4(client4.in()); task1.activate(THR_NEW_LWP | THR_JOINABLE); task2.activate(THR_NEW_LWP | THR_JOINABLE); task3.activate(THR_NEW_LWP | THR_JOINABLE); task4.activate(THR_NEW_LWP | THR_JOINABLE); task1.thr_mgr()->wait(); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception Caught:"); return 1; } return 0; }