verify.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: MIT */
  2. /* Copyright (c) 2013-2024 The SRS Authors */
  3. #include <stdio.h>
  4. #include <st.h>
  5. #include <assert.h>
  6. st_mutex_t lock;
  7. st_cond_t cond;
  8. void* start(void* arg)
  9. {
  10. printf("ST: thread run\n");
  11. printf("ST: thread wait for a while\n");
  12. st_usleep(1.5 * 1000 * 1000);
  13. printf("ST: thread wait done\n");
  14. int r0 = st_cond_signal(cond);
  15. printf("ST: thread cond signal, r0=%d\n", r0);
  16. printf("ST: thread lock\n");
  17. r0 = st_mutex_lock(lock);
  18. assert(r0 == 0);
  19. r0 = st_mutex_unlock(lock);
  20. printf("ST: thread unlock\n");
  21. return NULL;
  22. }
  23. int main(int argc, char** argv)
  24. {
  25. int r0 = st_init();
  26. assert(r0 == 0);
  27. printf("ST: main init ok\n");
  28. lock = st_mutex_new();
  29. cond = st_cond_new();
  30. st_thread_t trd = st_thread_create(start, NULL, 1, 0);
  31. printf("ST: main create ok\n");
  32. printf("ST: main lock\n");
  33. r0 = st_mutex_lock(lock);
  34. assert(r0 == 0);
  35. printf("ST: main cond waiting\n");
  36. r0 = st_cond_wait(cond);
  37. printf("ST: main cond wait ok, r0=%d\n", r0);
  38. r0 = st_mutex_unlock(lock);
  39. printf("ST: main unlock\n");
  40. st_thread_join(trd, NULL);
  41. printf("ST: main done\n");
  42. st_mutex_destroy(lock);
  43. st_cond_destroy(cond);
  44. return 0;
  45. }