int main(int ac, char* av[]) { LOG_MSG << "LogTestApp. -- written by Wilston Oreo."; #ifdef TEST_THREADS srand ( time(NULL) ); LOG_MSG_(1) << "Startup"; boost::thread thread1(threadLog); boost::thread thread2(threadLog); boost::thread thread3(threadLog); boost::thread thread4(threadLog); LOG_MSG_(1) << "Waiting for threads..."; thread1.join(); thread2.join(); thread3.join(); thread4.join(); #endif LOG_MSG_(1) << "Done"; LOG->level(2); LOG_MSG_(1) << fmt("Log level: %") % LOG->level(); LOG_WRN << fmt("Warning %") % 3; LOG_MSG_(3); LOG_MSG_(4); LOG_ERR << "ERROR"; return 0; }
void testThreadInitAndExit() { std::cout<<"****** Running thread start and delete test ****** "<<std::endl; { MyThread thread; thread.startThread(); } // add a sleep to allow the thread start to fall over it its going to. OpenThreads::Thread::microSleep(500000); std::cout<<"pass thread start and delete test"<<std::endl<<std::endl; std::cout<<"****** Running notify thread test ****** "<<std::endl; { NotifyThread thread1(osg::INFO,"thread one:"); NotifyThread thread2(osg::INFO,"thread two:"); NotifyThread thread3(osg::INFO,"thread three:"); NotifyThread thread4(osg::INFO,"thread four:"); thread1.startThread(); thread2.startThread(); thread3.startThread(); thread4.startThread(); // add a sleep to allow the thread start to fall over it its going to. OpenThreads::Thread::microSleep(5000000); } std::cout<<"pass noitfy thread test."<<std::endl<<std::endl; }
int main(int argc, char **argv) { Aria::init(Aria::SIGHANDLE_THREAD, false); ArMutex mutex; mutex.setLogName("mutex"); ArMutex::setLockWarningTime(1); ArMutex::setUnlockWarningTime(5); TestThread thread1(1, mutex), thread2(2, mutex), thread3(3, mutex), thread4(4, mutex); thread1.setThreadName("thread1"); thread2.setThreadName("thread2"); thread3.setThreadName("thread3"); thread4.setThreadName("thread4"); srand(time(0)); thread1.create(); thread2.create(); thread3.create(); printf("main thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", ArThread::getThisThreadName(), ArThread::getThisOSThread(), (unsigned int) ArThread::getThisThread()); printf("thread1 thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread1.getThreadName(), thread1.getOSThread(), (unsigned int) thread1.getThread()); printf("thread2 thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread2.getThreadName(), thread2.getOSThread(), (unsigned int) thread2.getThread()); printf("thread3 thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread3.getThreadName(), thread3.getOSThread(), (unsigned int) thread3.getThread()); printf("thread4 (not created yet) thread name=\"%s\", OS handle=%lu, OS pointer=0x%x\n", thread4.getThreadName(), thread4.getOSThread(), (unsigned int) thread4.getThread()); if(ArThread::getThisOSThread() == thread1.getOSThread() || ArThread::getThisOSThread() == thread2.getOSThread() || ArThread::getThisOSThread() == thread3.getOSThread() || ArThread::getThisOSThread() == thread4.getOSThread() || thread1.getOSThread() == thread2.getOSThread() || thread1.getOSThread() == thread3.getOSThread() || thread1.getOSThread() == thread4.getOSThread() || thread2.getOSThread() == thread1.getOSThread() || thread2.getOSThread() == thread3.getOSThread() || thread2.getOSThread() == thread4.getOSThread() || thread3.getOSThread() == thread1.getOSThread() || thread3.getOSThread() == thread2.getOSThread() || thread3.getOSThread() == thread4.getOSThread() || thread4.getOSThread() == thread1.getOSThread() || thread4.getOSThread() == thread2.getOSThread() || thread4.getOSThread() == thread3.getOSThread() ) { puts("error, some thread IDs are the same!"); return 5; } thread4.runInThisThread(); Aria::shutdown(); return(0); }
void main() { x = 0; y = 0; z = 0; a = 0; b = 0; thread1(); thread2(); thread3(); thread4(); }
// // Tests subscription creation by sending the similar concurrent subscription // creation requests . // void _testConcurrent(CIMClient &client) { CIMObjectPath filterPath; CIMObjectPath handlerPath; CIMObjectPath subscriptionPath; try { HandlerPath = CreateHandler1Instance(client, PEGASUS_NAMESPACENAME_INTEROP); FilterPath = CreateFilterInstance(client, QUERY1, "WQL", "Filter1", PEGASUS_NAMESPACENAME_INTEROP); Thread thread1(createSubscriptionFunc, (void *)0, false); Thread thread2(createSubscriptionFunc, (void *)0, false); Thread thread3(createSubscriptionFunc, (void *)0, false); Thread thread4(createSubscriptionFunc, (void *)0, false); thread1.run(); thread2.run(); thread3.run(); thread4.run(); thread1.join(); thread2.join(); thread3.join(); thread4.join(); _checkSubscriptionCount(client); PEGASUS_TEST_ASSERT(exceptionCount.get() == 3); DeleteInstance(client, SubscriptionPath, PEGASUS_NAMESPACENAME_INTEROP); DeleteInstance(client, FilterPath, PEGASUS_NAMESPACENAME_INTEROP); DeleteInstance(client, HandlerPath, PEGASUS_NAMESPACENAME_INTEROP); } catch(const CIMException &e) { PEGASUS_STD(cerr) << "Exception: " << e.getMessage() << PEGASUS_STD (endl); PEGASUS_TEST_ASSERT(0); } }
void MiscThreadTestCase::TestThreadDelete() { // FIXME: // As above, using Sleep() is only for testing here - we must use some // synchronisation object instead to ensure that the thread is still // running when we delete it - deleting a detached thread which already // terminated will lead to a crash! MyDetachedThread *thread0 = new MyDetachedThread(30, 'W'); CPPUNIT_ASSERT_EQUAL( wxTHREAD_MISC_ERROR, thread0->Delete() ); // delete a thread which didn't start to run yet. MyDetachedThread *thread1 = new MyDetachedThread(30, 'Y'); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread1->Run() ); wxMilliSleep(300); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread1->Delete() ); // delete a running thread MyDetachedThread *thread2 = new MyDetachedThread(30, 'Z'); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread2->Run() ); wxMilliSleep(300); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread2->Pause() ); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread2->Delete() ); // delete a sleeping thread MyJoinableThread thread3(20); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread3.Run() ); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread3.Delete() ); // delete a joinable running thread MyJoinableThread thread4(2); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread4.Run() ); wxMilliSleep(300); CPPUNIT_ASSERT_EQUAL( wxTHREAD_NO_ERROR, thread4.Delete() ); // delete a joinable thread which already terminated }
void update() { // Update our time static float t = 0.0f; static DWORD dwTimeStart = 0; DWORD dwTimeCur = GetTickCount(); if (dwTimeStart == 0) dwTimeStart = dwTimeCur; t = (dwTimeCur - dwTimeStart) / 1000.0f; dt = t - prev_time; prev_time = t; //gets cursor movement to update camera POINT currCursorPos; GetCursorPos(&currCursorPos); SetCursorPos(500, 500); g_Theta += (currCursorPos.x - 500) * 3.14159 / 180 / 10; g_Phi -= (currCursorPos.y - 500) * 3.14159 / 180 / 10; //this is for a panning camera //g_Theta = t / 3; //g_Phi = XM_PIDIV4 / 3; //add spheres if the spacebar key is pressed if (GetAsyncKeyState(VK_SPACE)) { float radius = (rand() % 150 + 100) / 100.0f; Sphere sphere(XMFLOAT3((rand() % 500 - 250) / 10.0f, (rand() % 250 + 250) / 10.0f, (rand() % 500 - 250) / 10.0f), XMFLOAT4((rand() % 100) / 100.0f, (rand() % 100) / 100.0f, (rand() % 100) / 100.0f, 1.0f), radius, radius * 200.0f); Spheres.push_back(sphere); } //multithread the simulation std::thread thread1(handle_collisions, 0, Spheres.size() / 4); std::thread thread2(handle_collisions, Spheres.size() / 4, Spheres.size() / 2); std::thread thread3(handle_collisions, Spheres.size() / 2, 3 * Spheres.size() / 4); std::thread thread4(handle_collisions, 3 * Spheres.size() / 4, Spheres.size()); thread1.join(); thread2.join(); thread3.join(); thread4.join(); //apply bounds for the spheres for (int i = 0; i < Spheres.size(); i++) { Spheres[i].ApplyForce(XMFLOAT3(0.0f, -9.8f * Spheres[i].Mass, 0.0f), dt); if (Spheres[i].Position.y - Spheres[i].Radius < 0) { Spheres[i].Position.y = Spheres[i].Radius; Spheres[i].Velocity.y *= -0.5f; } if (Spheres[i].Position.x - Spheres[i].Radius < -50.0f) { Spheres[i].Position.x = -50.0f + Spheres[i].Radius; Spheres[i].Velocity.x *= -0.5f; } else if (Spheres[i].Position.x + Spheres[i].Radius > 50.0f) { Spheres[i].Position.x = 50.0f - Spheres[i].Radius; Spheres[i].Velocity.x *= -0.5f; } if (Spheres[i].Position.z - Spheres[i].Radius < -50.0f) { Spheres[i].Position.z = -50.0f + Spheres[i].Radius; Spheres[i].Velocity.z *= -0.5f; } else if (Spheres[i].Position.z + Spheres[i].Radius > 50.0f) { Spheres[i].Position.z = 50.0f - Spheres[i].Radius; Spheres[i].Velocity.z *= -0.5f; } Spheres[i].Update(dt); } //makes the interface a little cleaner by restricting camera angles if (g_Phi > 3.14159 / 2) { g_Phi = 3.14159 / 2; } if (g_Phi < -3.14159 / 2) { g_Phi = -3.14159 / 2; } }
void calibrateEyeGaze() { //Note: Keep head fixed entire time //1. Display entire screen Mat screenImage(Size(640, 480), CV_8UC3, Scalar(255, 255, 255)); namedWindow("Calibration Screen", CV_WINDOW_NORMAL); setWindowProperty("Calibration Screen", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); imshow("Calibration Screen", screenImage); waitKey(0); //2. Display circles at 4 corners. circle(screenImage, Point(630, 10), 10, Scalar(255, 0, 0), -1); imshow("Calibration Screen", screenImage); waitKey(1000); calibrateStart = 1; thread thread1(aggregateEyeShift); waitKey(1000); calibrateStart = 0; thread1.join(); TopRight.x = threadReturn[0]; TopRight.y = threadReturn[1]; screenImage.setTo(Scalar(255, 255, 255)); circle(screenImage, Point(10, 10), 10, Scalar(255, 0, 0), -1); imshow("Calibration Screen", screenImage); waitKey(1000); calibrateStart = 1; thread thread2(aggregateEyeShift); waitKey(1000); calibrateStart = 0; thread2.join(); TopLeft.x = threadReturn[0]; TopLeft.y = threadReturn[1]; screenImage.setTo(Scalar(255, 255, 255)); circle(screenImage, Point(10, 470), 10, Scalar(255, 0, 0), -1); imshow("Calibration Screen", screenImage); waitKey(1000); calibrateStart = 1; thread thread3(aggregateEyeShift); waitKey(1000); calibrateStart = 0; thread3.join(); BottomLeft.x = threadReturn[0]; BottomLeft.y = threadReturn[1]; screenImage.setTo(Scalar(255, 255, 255)); circle(screenImage, Point(630, 470), 10, Scalar(255, 0, 0), -1); imshow("Calibration Screen", screenImage); waitKey(1000); calibrateStart = 1; thread thread4(aggregateEyeShift); waitKey(1000); calibrateStart = 0; thread4.join(); BottomRight.x = threadReturn[0]; BottomRight.y = threadReturn[1]; cout << "Top Right: " << TopRight.x << " " << TopRight.y << endl; cout << "Top Left: " << TopLeft.x << " " << TopLeft.y << endl; cout << "Bottom left: " << BottomLeft.x << " " << BottomLeft.y << endl; cout << "Bottom Right: " << BottomRight.x << " " << BottomRight.y << endl; screenImage.setTo(Scalar(255, 255, 255)); //3. Record the eye shift in all 4 locations //4. Linearly interpolate eye shifts to find gaze position }
int main(int argc, char* argv[]) { try { pid_t pid; ::mooon::sys::g_logger = new sys::CSafeLogger(".", "test.log"); sys::g_logger->set_single_filesize(20240000); sys::g_logger->set_backup_number(10); MYLOG_INFO("hello"); MYLOG_ERROR("world"); for (int i=0; i<10; ++i) { pid = fork(); if (-1 == pid) { fprintf(stderr, "fork error: %m\n"); exit(1); } else if (0 == pid) { // 子进程 sys::CThreadEngine thread1(sys::bind(&foo)); sys::CThreadEngine thread2(sys::bind(&foo)); sys::CThreadEngine thread3(sys::bind(&foo)); sys::CThreadEngine thread4(sys::bind(&foo)); sys::CThreadEngine thread5(sys::bind(&foo)); thread1.join(); thread2.join(); thread3.join(); thread4.join(); thread5.join(); exit(0); } } // 等待所有子进程结束 while (true) { int status = -1; pid = wait(&status); if (pid > 0) { printf("process[%u] exit with %d\n", pid, status); } else { if (ECHILD == errno) { break; } else { printf("unknown error when waiting child\n"); break; } } } } catch (sys::CSyscallException& syscall_ex) { fprintf(stderr, "%s\n", syscall_ex.str().c_str()); exit(1); } return 0; }