1 #include <posix/timer.h> 2 3 #include <iostream> 4 #include <thread> 5 6 using namespace std; 7 8 #define TEST_COUNT 10 task0_entry(void)9static void task0_entry(void) 10 { 11 int i; 12 13 for (i = 0; i < TEST_COUNT; i++) { 14 sleep(1); 15 cout << "I'm task0" << endl; 16 } 17 } 18 task1_entry(void)19static void task1_entry(void) 20 { 21 int i; 22 23 for (i = 0; i < TEST_COUNT; i++) { 24 sleep(1); 25 cout << "I'm task1" << endl; 26 } 27 } 28 thread_test(void)29void thread_test(void) 30 { 31 int cpu_num; 32 33 cout << "thead test start" << endl; 34 thread thread0(task0_entry); 35 thread thread1(task1_entry); 36 thread0.join(); 37 thread1.join(); 38 #if 0 39 cpu_num = thread0.hardware_concurrency(); 40 if (cpu_num <= 0) { 41 cout << "thead test error, cpu_num:" << cpu_num << endl; 42 return; 43 } 44 #endif 45 46 cout << "thead test ok" << endl; 47 } 48