1 #include <pthread.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 6 constexpr int LOOP_COUNT = 100000000; 7 ChildThreadFunction(void *)8void* ChildThreadFunction(void*) { 9 for (volatile int i = 0; i < LOOP_COUNT; ++i) { 10 } 11 return nullptr; 12 } 13 MainThreadFunction()14void MainThreadFunction() { 15 for (volatile int i = 0; i < LOOP_COUNT; ++i) { 16 } 17 } 18 main()19int main() { 20 while (true) { 21 pthread_t thread; 22 int ret = pthread_create(&thread, nullptr, ChildThreadFunction, nullptr); 23 if (ret != 0) { 24 fprintf(stderr, "pthread_create failed: %s\n", strerror(ret)); 25 exit(1); 26 } 27 MainThreadFunction(); 28 ret = pthread_join(thread, nullptr); 29 if (ret != 0) { 30 fprintf(stderr, "pthread_join failed: %s\n", strerror(ret)); 31 exit(1); 32 } 33 } 34 return 0; 35 } 36