2
0

thread-join.cpp 856 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. g++ thread-join.cpp ../../objs/st/libst.a -g -O0 -o thread-join && ./thread-join
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "../../objs/st/st.h"
  7. void* pfn(void* arg) {
  8. printf("pid=%d, coroutine is ok\n", ::getpid());
  9. return NULL;
  10. }
  11. int main(int argc, char** argv) {
  12. st_init();
  13. printf("pid=%d, create coroutine #1\n", ::getpid());
  14. st_thread_t thread = st_thread_create(pfn, NULL, 1, 0);
  15. st_thread_join(thread, NULL);
  16. st_usleep(100 * 1000);
  17. printf("pid=%d, create coroutine #2\n", ::getpid());
  18. thread = st_thread_create(pfn, NULL, 1, 0);
  19. st_thread_join(thread, NULL);
  20. st_usleep(100 * 1000);
  21. printf("pid=%d, create coroutine #3\n", ::getpid());
  22. thread = st_thread_create(pfn, NULL, 1, 0);
  23. st_thread_join(thread, NULL);
  24. printf("done\n");
  25. st_thread_exit(NULL);
  26. return 0;
  27. }