int main() { foo f; { boost::thread testThread(boost::bind(&foo::abc, &f)); } { boost::thread testThread(&foo::abc, &f); } { boost::thread testThread(&foo::abc, boost::ref(f)); } return 0; }
int main() { testThread(); testAtomic(); return 0; }
int FThread::setFunParam(const ft_funparam_t *p_fp) { int ret = testThread(); if (ret) { return ret; } ::memcpy(&this->funparam, p_fp, sizeof(this->funparam)); return 0; }
void WorkerQtTest::postFromOutsideTest() { TestHandler handler; std::thread testThread(std::bind(&runFromOutsideTest, std::ref(handler), m_worker)); m_worker->getFuture().wait(); RUN_BASIC_TEST_CHECKS(handler); testThread.join(); }
int main (int argc, char *const *argv) { int errorCount = 0; errorCount += testStartError (); errorCount += testStartStop (); errorCount += testExternalRun (); errorCount += testThread (); errorCount += testMultithread (); if (errorCount != 0) fprintf (stderr, "Error (code: %u)\n", errorCount); return errorCount != 0; /* 0 == pass */ }
int FThread::start() { int ret = testThread(); if (ret) { return ret; } void *p_fp = ::malloc(sizeof(this->funparam)); // free by startThread if pthread_create call success !!! ::memcpy(p_fp, &this->funparam, sizeof(this->funparam)); ret = ::pthread_create(&this->threadHandle, NULL, startThread, p_fp); if (ret) { this->threadHandle = 0; ::free(p_fp); return ret; } return 0; }
int main() { printf("This works %d%%\n", 100); printf("Hello World!\n"); printf("Norm nums: %d %u %x %c %s%s", -1, -2, 0xabcdefab, 'X', "x", "\n"); // Note: these don't work with __simple_printf! printf("BFill nums: %4d %12u %10x %3c %3s%s", -1, -2, 0xabcdefab, 'X', "x", "\n"); printf("LFill nums: %04d %012u %010x %3c %3s%s", -1, -2, 0xabcdefab, 'X', "x", "\n"); #pragma GCC diagnostic ignored "-Wformat" // The underlying library actively ignores the zeros -- we want to test it! printf("RFill nums: %-04d %-012u %-010x %-3c %-3s%s", -1, -2, 0xabcdefab, 'X', "x", "\n"); // The underlying library detects and handles this error - we want to test it! printf("%"); #pragma GCC diagnostic warning "-Wformat" #ifdef __TINY_IO_H putstr("Put* nums: "); putdec(-1); putchar(' '); putudec(-1); putchar(' '); puthex(0xabcdefab); putchar(' '); putchar('X'); putchar(' '); putstr("x"); putchar(' '); putfnum(0xabcdefab, 16, 0, 10, '0'); putchar('\n'); putlhex(-10000000000L); putchar(' '); putldec(-10000000000L); putchar(' '); putlfnum(0xabcdefabcdef, 16, 0, 16, '0'); putchar('\n'); #endif char buf[80]; sprintf(buf, "Norm nums: %d %u %x %c %s", -1, -2, 0xabcdefab, 'X', "x"); puts(buf); int d; unsigned u, x; char c; char s[20]; int n = sscanf(buf, "Norm nums: %d %u %x %c %s\n", &d, &u, &x, &c, s); printf("Scan nums: %d %u %x %c %s (%d scanned)\n", d, u, x, c, s, n); printf("\nGimme a character: "); char ch = getchar(); printf("\nYou typed: "); putchar(ch); putchar('\n'); int age; do { printf("\nHow old are you? "); scanf("%u", &age); } while (!age); printf("In ten years, you'll be: %d\n\n", age + 10); sprintf(buf, "BFill nums: %4d %12u %10x %3c %3s", -1, -2, 0xabcdefab, 'X', "x"); puts(buf); n = sscanf(buf, "BFill nums: %4d %12u %10x %3c %3s\n",&d, &u, &x, &c, s); printf("Scan nums: %d %u %x %c %s (%d scanned)\n", d, u, x, c, s, n); sprintf(buf, "LFill nums: %04d %012u %010x %3c %3s", -1, -2, 0xabcdefab, 'X', "x"); puts(buf); n = sscanf(buf, "LFill nums: %04d %012u %010x %3c %3s\n",&d, &u, &x, &c, s); printf("Scan nums: %d %u %x %c %s (%d scanned)\n", d, u, x, c, s, n); #ifdef __TINY_IO_H printf("\nEnter a string up to 4 characters: "); safe_gets(s, 5); printf("You entered: %s\n", s); printf("\nEnter a decimal: "); d = getdec(); printf("You entered: %d\n", d); printf("\nEnter an unsigned decimal: "); u = getudec(); printf("You entered: %d\n", u); printf("\nEnter a hex number: "); u = gethex(); printf("You entered: %x\n", u); printf("\nEnter a 1-4 digit number: "); d = getfnum(10, 1, 4); printf("You entered: %d\n", (int)d); long long ld; unsigned long long lu, lx; printf("\nEnter a long long decimal: "); ld = getldec(); printf("You entered: "); putldec(ld); putchar('\n'); printf("\nEnter an unsigned long long decimal: "); lu = getludec(); printf("You entered: "); putludec(lu); putchar('\n'); printf("\nEnter a long long hex number: "); lx = getlhex(); printf("You entered: "); putlhex(lx); putchar('\n'); printf("\nEnter a 1-12 digit long long number: "); ld = getlfnum(10, 1, 12); printf("You entered: "); putldec(ld); putchar('\n'); #endif _serialLock = 1; printf("\n\nMultithreaded tests.\n" "Note this will be quite messed up because multiple cogs\n" "will be doing I/O on a character-by-character basis...\n"); _start_cog_thread(threadStack(0), &testThread, (void*)1, &tls[0]); _start_cog_thread(threadStack(1), &testThread, (void*)2, &tls[1]); testThread(0); printf("\nBye!\n"); return 0; }
void Robot::OperatorControl() //teleop code { CameraServer::GetInstance()->SetQuality(50); CameraServer::GetInstance()->StartAutomaticCapture("cam0"); bool testThreadRun = true; bool updateThreadRun = true; std::thread testThread(threadTestFunction, &testThreadRun); std::thread updateThread(updatePositionFunction, &updateThreadRun, &driveStick, &position); float throttle; float moveValue; float rotateValue; float shooterSpeed; float shooterAngle; shooter.Enable(); driveTrain.Enable(); while(IsOperatorControl() && IsEnabled()) { throttle = (((-driveStick.GetRawAxis(Constants::driveL2)) + 1.0)/2.0); //[0, 1] moveValue = throttle * driveStick.GetY(); rotateValue = -driveStick.GetX(); shooterSpeed = -driveStick.GetRawAxis(Constants::driveRightStickY); //change shooterAngle = 0; //change SmartDashboard::PutNumber("Throttle Value", throttle); SmartDashboard::PutNumber("Move Value", moveValue); SmartDashboard::PutNumber("Rotate Value", rotateValue); float shooterSpeed = -driveStick.GetRawAxis(Constants::driveRightStickY); if (shooterSpeed < -0.35) { shooterSpeed = -0.35; } driveTrain.ArcadeDrive(moveValue, rotateValue, true); shooter.SetSpeed(shooterSpeed, -shooterSpeed); if (driveStick.GetRawButton(Constants::calibrateButton)) { position.Calibrate(); } if (driveStick.GetRawButton(Constants::shootButton)) { if (!shooter.HasBall()) { shooter.LoadBall(); } if (shooter.HasBall()) { shooter.PrepareShooter(shooterAngle, shooterSpeed); //TODO: Change these. Get physics major's equation } Wait(1); //how long to wait to shoot. Will need to be adjusted with testing if (shooter.Angle() > shooterAngle - 2 && shooter.Angle() < shooterAngle + 2 && shooter.WheelSpeed() == shooterSpeed) { shooter.Shoot(); } } SmartDashboard::PutNumber("xPos", position.GetX()); SmartDashboard::PutNumber("yPos", position.GetY()); SmartDashboard::PutString("Version", "Noah 2/14/16, 11:16 PM"); } shooter.Disable(); driveTrain.Disable(); testThreadRun = false; testThread.join(); updateThreadRun = false; updateThread.join(); driveTrain.SetSafetyEnabled(true); }