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